Storing Images and Running Containers

Storing Images

Docker Hub :

Docker Hub is a service provided by Docker for finding and sharing container images.

Visit 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:

  1. 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.
  2. Tag the image with repository name and tag (or version number) using docker tag command.
$ docker login
Login Succeeded


$ docker images
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 []
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 
  • And more…..

We can run our own local registry using docker “registry” image. 

$ docker run -d -p 5000:5000 
--restart always 
--name registry 

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

Run containers using the docker images with “docker run” command.

Syntax : docker run [options] image:tag

$ docker run -d 
--name mywebsite 
-p 8080:80 

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>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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s