Docker Push | How to push Docker Images to Dockerhub?


You can use the Docker push command to push images to the Docker hub. Docker hub allows us to create repositories where we can store and manage Docker images. Repositories are a set of similar images identified by their tags. For example, Docker contains several versions of Ubuntu images inside the Ubuntu repository. Each Ubuntu image is identified by a separate tag such as xenial, 18.04, 20.04, focal, etc.

Pushing images to the Docker hub is fairly simple. Once you have pushed images to the Docker hub, you can easily share them with your organization members. In fact, you can even use the Docker push command to push images to your private and locally hosted repositories. You can create local private registries using the registry image that the Docker hub provides.

You just need to run a container of the registry image, tag your images in the form of localhost:5000/<image-name> and execute the Docker push command. The daemon will automatically push it to your private registry.

In this article, we will see how to push an image to Docker hub. Before we move ahead, check out our article on What are Docker registries and how to create a repository in Dockerhub?. Also, check out our completely free Docker Tutorial for Beginners.

To understand this topic better, you should know about the following concepts.

  1. What are Docker Images?
  2. How to Build Docker Images?
  3. How to Pull Docker Images?

Creating a Docker hub repository

First of all, you need to have a Docker hub repository created where you can push your images. Let’s create a new repository called myubuntu where we will push a customized ubuntu image.

To do so, you need to have a Docker hub account. You can create one here. After you are done, click on the create a repository link to start creating the repository on the Docker hub.

Create a Docker hub repository
Create a Docker hub repository

After you have entered all the details, click on the create link below. You have now successfully created the myubuntu repository. You can see the two commands written in the pro tip section. These are used to tag the image to the repository and then push it to the Docker hub.

Next, Log In to Docker Hub through Command line using the Docker login command.

$ docker login

It will prompt you to enter your username and password.

Docker login
Docker login

Create a Docker Image to Push

Now, we need to create an Image. You can check out this guide on how to build Docker Images? For this example, we will pull an Ubuntu image from Dockerhub and run a container associated with that image. To do so, we can use the following command.

$ docker pull ubuntu
Pull Ubuntu Image
Pull Ubuntu Image

Now, let’s list all the images.

$ docker images
List Docker Images
List Docker Images

You can see that our Ubuntu image has been pulled successfully.

Tag the Docker Image

The next step is to tag the Ubuntu image so that the daemon knows on which repository to push the image. To do so, we can use the Docker tag command.

$ docker tag local-image:tag-name username/reponame:tagname

Since we want to push the Ubuntu:latest image in our local machine to the myubuntu repository on Docker hub account with user name iamrj846, we can use the following command.

$ docker tag ubuntu:latest iamrj846/myubuntu:myubuntutag

Once done, list all the images to verify.

Tag Docker Images
Tag Docker Images

Push Image to Docker Hub

The general syntax of the Push command is –

$ docker push [OPTIONS] NAME[:TAG]

The following options can be used along with this command.

NameShorthandDescription
--all-tags -aIf you want to push all the tagged images of the particular image name, you can use this option.
--disable-content-trustYou can use this to skip the signing of the images.
--quiet -qYou can use quiet option to suppress the verbose output.
Options for Docker Push command

Now, it’s time to push the image to the Docker hub.

$ docker push <username>/<reponame>:<tagname>

Here, we need to specify the username, repository name, and the tag of the image.

$ docker push iamrj846/myubuntu:myubuntutag
Docker Push Image
Docker Push Image

To verify whether the image has been pushed or not, you can navigate to the tags section in your myubuntu repository.

Docker Push to Docker Hub
Docker Push to Docker Hub

If you want to pull this image back, you can use the following command.

$ docker pull iamrj846/myubuntu:myubuntutag

Final Thoughts!

In this article, we discussed how to push images to the Docker hub using the Docker push command. We saw how to create a Docker hub repository, tag images, and push the tagged image to the repository.

If you have any queries or suggestions, please mention them in the comment and we will have our experts get back to you.

Recommened Articles –

  1. What is Docker?
  2. Docker Registry | What are Docker Registries and Docker Hub?
  3. How to Build Docker Images?
  4. How to Pull Docker Images?

Happy Learning!

One comment

Leave a Reply