Skip to main content

Tagging and Pushing Images to DockerHub

Hands-On Lab

 

Photo of Travis Thomsen

Travis Thomsen

Course Development Director in Content

Length

00:30:00

Difficulty

Intermediate

You have just completed building a Dockerfile, and you are ready to push it to Docker Hub. First make sure that you have a Docker Hub account. Then build your image with the VERSION build argument that is set to 1.5. Finally, tag the image to latest, and push both images to Docker Hub.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Tagging and Pushing Images to DockerHub

The Scenario

We've just completed building a Dockerfile, and we're ready to push it to Docker Hub. We need to build our image with the VERSION build argument that is set to 1.5, then tag the image to latest, and finally push both images to Docker Hub.

Logging Into the Lab

First make sure that you have a Docker Hub account. We'll need it to complete the lab. Then log into the environment using the credentials provided on the lab overview page, either in a terminal session on your local machine or by clicking Instant Terminal.

Log in to Docker Hub

Login to Docker Hub:

[cloud_user@host]$ docker login -u [DOCKER_HUB_USERNAME]

Get the Git Commit Hash

Use Git commit hash as the image tag:

[cloud_user@host]$ cd weather-app
[cloud_user@host]$ cd src
[cloud_user@host]$ git log -1 --pretty=%H

The next line will be the has we need.

Build the weather-app Image

Now let's move up a directory and build the image:

[cloud_user@host]$ cd ../
[cloud_user@host]$ docker image build -t [USERNAME]/weather-app:[HASH] --build-arg VERSION=1.5 .

Tag the weather-app Image as Latest

[cloud_user@host]$ docker image tag [USERNAME]/weather-app:[HASH] [USERNAME]/weather-app:latest

Push Both Images to Docker Hub

[cloud_user@host]$ docker image push [USERNAME]/weather-app:[HASH]
[cloud_user@host]$ docker image push [USERNAME]/weather-app:latest

Conclusion

That's it! We built a Docker image, tagged it as latest and got it pushed up to Docker Hub. Congratulations!