Pushing Repositories to Docker Hub

While working with Docker, you’ll often spend time pushing and pulling single images or full image repositories to and from the public Docker registry. The Docker registry is an online public location, commonly known as Docker Hub, where you store your Docker images. Images are organized in repositories, which are sort of directories containing one or more images from the same source but with different tag.

You can for instance, have a base minimal Ubuntu image tagged as v1.0, and the same Ubuntu image with some additional packages installed and tagged as v2.0. You would group these images in a public or private repository on Docker Hub.

In fact, a repository can also be created locally on your Docker host where you’ll have all your images on your local server, but this is not considered a best practice, because of the risk to loose all your customized images should any unexpected failure happens to the Docker host.

This is why it’s a common practice to link then push your local repositories to Docker Hub. Hence, having all your images online, protected from any eventual failure, and available to any host that can actually connect to Docker Hub.

Docker images can also be pushed to an on-premise registry when you have the Docker Trusted Registry installed in your environment, but this features comes only with the Enterprise Edition of Docker.

In this post we will go through the steps on how to push your local repository containing your different customized and tagged images to Docker Hub.

We have on an Ubuntu local image hosted on a Docker host that we will use for this demonstration. It has the latest tag.

Using the tag argument, the command syntax looks like this:

So to create a tagged image from the ubuntu image and place it in a local repository named mouradn81, we will use the following command:

Because we want to push this local repository to the online registry, the repository name needs to match your Docker ID because this is the base name for any Docker online repository.

We have now two Ubuntu images, one of them is in the local repository mouradn81 and tagged v1.0.

Note that both images have the same IMAGE ID value, which is normal, they are the same object but tagged differently.

Similarly, let’s create two other images, each with one different tag

Tagging the same image does not have much sense. An image is usually tagged after some changes have been applied to it, like for instance, installing some dependencies and libraries using a Docker File. In our case, this is just a demo to show the tag argument use case to have three different images.

We now have three local images in our local repository

Time now to push our local repository to the public Docker registry. The first thing to do is to login to Docker Hub. If you don’t have a Docker ID, create one from here.

Currently, I have only one repository visible from my Docker Hub Dashboard.

Let’s login from the Docker CLI.

Once logged in, you can proceed with the repository push.

If everything goes fine, you’ll have an output similar to this.

Repository pushed. If we check now the Docker Hub Dashboard, we can see that our repository is there.

On the repository, click Details then Tags to see the image tags.

Now from another host that does not have any image yet.

You should be able to pull back down the images previously pushed up to Docker Hub.

Once complete, your image should be present again on your local host.

 

Find this post interesting. Share it!

Leave a Comment

Your email address will not be published. Required fields are marked *