Pushing images to Docker Repository

Today, in this post I am going to explain the steps needed for publishing an image in your local Docker daemon to the Docker hub.

Docker hub is central registry of images maintained by Docker. We can use the images to build containers by downloading them into the local machine. For example, in of the previous post, I showed you how to build and deploy .NET core apps in Docker. This was done by downloading the .NET Core image from the Docker repository to my local machine and created the console application using the downloaded image and deployed it to a container.

You can access the public repository of Microsoft for Docker images @ https://hub.docker.com/u/microsoft/

The main difference between a registry and repository in Docker terms is that, Registry can be hosted by a third party like Docker hub, Google Container Registry where as a docker repository is collection of different images with same name but with different tags.

So let's see how can we push our image in the Docker repository.

Step 1 : Create an account in Docker Hub.

It's necessary that you should have an account with Docker for maintaining your repositories. So if you haven't created one yet, goto http://hub.docker.com and create if before proceeding to the next steps.

Step 2 : Create an Image locally.

Please refer my earlier post here to how to create a console application using .NET Core in Docker. I am going to reuse the image created in that post for pushing it into the public repository.

Step 3 : Tagging the Image

After building the docker image, you can get all the images available in your local daemon using the docker images command.

So if you haven't specified any tag while building the image, Docker will automatically set the tag as latest. Let's give a different tag name for our image using the following command.

Syntax

docker tag <exiting repo name>:<tag name> <user name>/<repository name>:<labe>

Usage

docker tag docker-build-sample:latest xxxx/docker-build-sample:mobconf

So the above command will tag our existing repository name as xxxx/docker-build-sample (replace xxxx with your username) and tag name as mobconf

Step 4 : Pushing the Image

To push the image from your local docker daemon to the the Docker Hub registry, you need to login first into to account we created in Step 1. This can be done from the command prompt using the docker login command.

Once you are logged in, we push the image using the following command

Syntax

docker push <repository name>:<tag name>

Usage

When you execute the command, docker will first create a public repository if it can't found the one provided in the push command, then start pushing the layers to the registry and will show the progress as shown in the image above.

Step 5: Viewing the Repository.

When it completes the upload of the image, then you can view it in the registry by going to your account in Docker Hub. In the landing page it will list the repositories you have and clicking on it will lead you to a page like the one given below.

If you go to the tags section, we will see the tag we created from the command prompt.

  

So you can see that from the Tags section that our image is around 100 M in size. Let's create a new tag for the existing image in local and push it to central repository and see if what happens.

Here, I have created a new tag named latest for our repository and when I pushed that image it's not uploading all the layers again. That's because since both the tags are using the same images there is no need to upload that again to the repository and Docker has this great mechanism of sharing the resources. So if you look at the tags section now, it will show two images with exactly the same size but in reality it's sharing the same layers.

  

   Given below is a screenshot of the comparison of the images I made in imagelayers.io to visualize the layers in the image. You can clearly see that up to WORKDIR command, both the images are sharing the layers


No Comments

Add a Comment