Docker Hub :
Docker Hub is a service provided by Docker for finding and sharing container images.
Visit https://hub.docker.com and create an account to store your images.
You can create any number of public repositories. Docker providers only one private repository for free. If you want more no.of private repositories, you can upgrade the plan.
We can push the image to the docker hub with “docker push” command. Before that, we need to do two things:
- Login to the docker hub using “docker login” command and provide username and password. Once successfully authenticated, you don’t need to login every time until you logged out using “docker logout” command.
- Tag the image with repository name and tag (or version number) using docker tag command.
$ docker login Username: Password: Login Succeeded $
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE mywebsite latest 44870583de0c 2 minutes ago 380MB centos 7 1e1148e4cc2c 2 months ago 202MB $
$ docker tag 44870583de0c learninghub/website:1.0
$ docker push learninghub/website:1.0 The push refers to repository [docker.io/learninghub/website] bc6f85aad9de: Pushed 1d1fc5de57b2: Pushed 071d8bd76517: Mounted from library/centos 1.0: digest: sha256:4ff5eef21cc80f609d20064c62cf2f9caa3c27a363324732c9d83442b141beb3 size: 948 $
We can also store the images in the private repositories offered by different cloud providers.
- Elastic Container Registry by AWS
- Azure Container Registry by Microsoft Azure
- Google Container Registry by Google
- Docker Trusted Registry by Docker
- Docker Registry by Quay.io
- And more…..
We can run our own local registry using docker “registry” image.
$ docker run -d -p 5000:5000 --restart always --name registry registry:2
To Store images in the local registry, tag the image with localhost:5000.
$ docker tag 44870583de0c localhost:5000/website:1.0 $ docker push localhost:5000/website:1.0
Run containers using the docker images with “docker run” command.
Syntax : docker run [options] image:tag
$ docker run -d --name mywebsite -p 8080:80 mywebsite:latest 1c63111fed79a373b4cdc2ede2bf72f33139e0d90e124eec999790b47c65af8d $
Here, -d for run in background ( as daemon), -p for to map host to container port (HostPort:ContainerPort).
To check the running containers, use “docker ps” commands.
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1c63111fed79 mywebsite:latest "/usr/sbin/httpd -D …" 4 minutes ago Up 4 minutes 0.0.0.0:8080->80/tcp mywebsite
Now, access the website using http://HOST-IP:8080
To run the container use, “kubectl run” command or create a yaml.
$ kubectl run mywebsite --image=learninghub/website:1.0 deployment.apps "mywebsite" created
To check the pods, use kubectl get pods
$ kubectl get pods NAME READY STATUS RESTARTS AGE mywebsite-5c588f6774-zmlzp 1/1 Running 0 54s
To Access the website, we have to create a service for this deployment, using “kubectl expose” command.
$ kubectl expose deployment mywebsite --port=80 --type=NodePort service "mywebsite" exposed
You can access the website using worker node IP address.
If you have kubernetes cluster in the cloud, you can create a service with load balancer as well.