Upload Image to Docker Hub

Hey developers! Today we are going to see how to upload docker image to Docker Hub. So, let’s say you have a project of which you’ve created a docker image. Awesome! Now you need to store it in an online repository so that you, and everyone can pull the same image. That remote repository could be a number of places. But for our example, we will use the Docker Hub container registry to publicly upload our docker image. So, let’s begin. 


Table of Content

  1. Log in to Docker Hub Locally
  2. Tag the Docker Image
  3. Push the Image to Docker Hub
  4. Pull Image from Docker Hub Registry
  5. Resolving Docker Issues
  6. FAQ

STEP 1: Login to Docker Hub From Command Line

To begin with, in order to login to docker hub from command line, make sure that the Docker service is enabled. If you are on Windows, then open the Docker Desktop tool. Next, you need to login to Docker Hub. Thus, open a terminal or CMD if on windows. I am using GitBash.

Open your Commandline and execute the following command:  

					docker login  

This would ask you for your Docker Hub username and password.  Just login by entering your credentials and it will prompt “Login Successful 

STEP 2: Tag Docker Image

Next, you would tag Docker image so that it is uniquely identifiable when pulling the image. Let’s take the Docker image that I already have on my computer, named ubuntu. To attach a tag name, execute the following command:  

					// command format: docker tag IMAGE_NAME USERNAME/NEW_NAME:TAG 

docker tag ubuntu daniyal1217/my_ubuntu_image:0.0.1
  • IMAGE_NAME is the name of the image on my local machine named “ubuntu” 
  • USERNAME is the username of the Docker Hub  
  • NEW_NAME is the new name you may want to give to the image. It can remain the same too. 
  • TAG is the unique identifier. Usually, it’s given the version number of the project. 
**Note: The TAG name MUST start with your Docker Hub username. Followed by a forward slash “/” and then the version number.

As a result of the above command execution, a new image would now have been built. To check it, execute the following command to list all the images.  

					docker images 

Take reference from below image:  

Tagged a Docker Image before Publishing to Docker Hub
Tagged a Docker Image before Publishing to Docker Hub

Create Image From Dockerfile

If you have a custom Dockerfile,  from which you want to create an image while assigning a tag; then execute the following command: 


docker build tag ubuntu daniyal1217/my_ubuntu_image:0.0.1 .

The dot “.” at the end of the above command denotes the location of the Dockerfile in your project.

How to remove Tags from Docker Image

					// docker remove tag from image

STEP 3: Push an Image to Docker Hub

Finally, we are ready to push local image to docker hub. Simply execute the following command to publish it to your repository.  

					docker push daniyal1217/my_ubuntu_image:0.0.1 

And you are done! Open Docker Hub account and see the published image there, as shown in the image below: 

Successfully Uploaded Docker Image to Docker Hub
Successfully Uploaded Docker Image to Docker Hub

STEP 4: How to Pull Image From Docker Hub

To pull the image to any other machine, simply go to the image repository you pushed on Docker Hub. On the right-hand side, you will see the command to pull image from docker hub into your machine. Take reference from the image below:  

How to Pull Docker Image from Docker hub
How to Pull Docker Image from Docker hub

Simply copy and paste the command to your terminal or CMD and the image would get downloaded. From there just execute the ‘docker run IMAGE_NAME:TAG’ command to run its container.  

STEP 5: Resolving Docker Issues

1. Restart Docker Services 

Before anything else, make sure to enable or restart Docker services. If you are on Linux or Mac, then run these commands:  

					sudo systemctl stop docker 

sudo systemctl start docker 

To start docker service windows, simply open Docker Desktop that you installed on your windows machine. 

2. Username when tagging Docker Image 

When you publish your docker image, it needs a location of the account to publish in. That will be your Docker Hub account location. Which it will identify when you add your Docker Hub account username while you are attaching a tag to the Docker image. 


3. Retry Logging in  

If it’s still not working, it’s worth trying to log out and log back in again. To do that, execute these commands: 

					docker logout  

docker login 


Yes! Public repositories are free. However, you only get 1 private repository and would have to pay to get more private repositories. 

Read here to get more info: Docker Hub Documentation

Yes it is. Currently Docker Hub container registry is housing 3.5 million repositories as of 2020.

As claimed by Docker themselves: ?

“Docker containers are, by default, quite secure; especially if you run your processes as non-privileged users inside the container.”

  1. Amazon Elastic Container Registry (ECR)
  2. JFrog Artifactory
  3. Azure Container Registry
  4. Google Container Registry
  5. Nexus Repository Manager

That’s a wrap!

I hope this tutorial helped you learn how to upload Docker image to Docker Hub. You may also want to learn how to publish Angular library to NPM or how to upload Maven packages to Nexus OSS 3.

Have a great one!