In this tutorials, I am going to show how to push docker image to docker hub.

push docker image to docker hub:

We have discussed everything in our previous tutorials about how to build a spring boot application as a docker image and how to run it docker command.

Here we will see the recommended steps to push this docker image to docker hub.

Step 1: Create your docker hub account.

Step 2: Click on create the repository.

Step 3: Install docker on your machine.

Step 4: Open the terminal window and log in to docker account by using below command.

Terminal
$docker login --username=your_docker_user_name

It will ask you to enter the docker password, upon successful login you should see the below logs.

Terminal
$docker login --username=your_docker_user_name
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

Step 5: Get docker images list in your machine by using the below command.

Terminal
$docker images
Push docker image to docker hub

As we see in the above picture, I have multiple docker images running on my machine. Now I would like to push the spring-boot-docker image to docker hub.

Step 6: Create a tag for your local image for the remote repository.

Note: Tag name should be equal to image id.

Terminal
$docker tag 14a9f0ebbf02 your_docker_user/your_docker_repo/spring-boot-docker:v1

Step 7: Push the image to docker hub.

Terminal
[email protected]:Spring-boot-docker# docker push your_docker_user/spring-boot-docker
The push refers to repository [docker.io/your_docker_user/spring-boot-docker]
33e31b121204: Pushed 
d97f26ef1623: Pushed 
e87475e5811f: Pushed 
51e6d0a07219: Pushed 
ba57bc494b22: Pushed 
3443d6cf0f1f: Pushed 
f3a38968d075: Pushed 
a327787b3c73: Pushed 
5bb0785f2eee: Pushed 
latest: digest: sha256:5272bc835665f73fc096f89a7dc3383155e24737811a07361463a9e140dbda02 size: 2213

Step 8: Go to docker hub account and refresh your repositories list, there you can see your image.

References:

Happy Learning 🙂