Search Tutorials


Publishing Docker Image to DockerHub | JavaInUse

Publishing Docker Image to DockerHub

In this tutorial we will be pushing docker image to dockerhub. Docker Hub is the world's largest library and community for container images. Using Docker Hub we can upload the images we need to share. These can then be downloaded as needed.

DockerHub Image Share

Usually organizations make use of their own private repositories for storing docker images. In the next tutorial we will looking at what is a docker swarm and how to use it.

Docker Tutorial - Table Of Contents

Docker Deploying Spring Based WAR Application to Docker Deploying Spring Based JAR Application to Docker Deploying Multiple Spring Boot Microservices using Docker Networking Deploying Multiple Spring Boot Microservices using Docker Compose Deploying Spring Boot + MYSQL Application to Docker Publishing Docker Image to DockerHub Deploy Docker Swarm services using Play With Docker Deploy Docker Swarm services using Docker Stack Deploy Docker Swarm services to multiple AWS EC2 instances Docker Cheat Sheet

Video

This tutorial is explained in the below Youtube Video.

Lets Begin-

In previous tutorials we have developed a spring boot microservice which exposes API to get Employee information. We also created the docker image for the employee-producer. In this tutorial we will be creating a Docker Hub account and pushing the image to the Docker Hub
  • Go to Docker Hub Website
    DockerHub Home Page
  • If you do not have an account create a new one by clicking on Sign up for Docker Hub
    DockerHub SignUp Page

  • Once account is created sign in to the docker hub account. We will not see any images in our account.
    DockerHub Page
  • Previously we have created an image named employee-producer. We will be pushing this image to Docker Hub. Using following command we can list the images present-
     docker image ls
    

    Docker List Images
  • Using the terminal login to the docker hub account. It will ask for the dockerhub username and password.
    docker login
    

    Docker Terminal Login

  • Next we will push the image named employee-producer to docker hub using the following command.
    docker image push employee-producer
    
    But we get the following exception
    Docker Image Upload Exception
  • This is because only official docker images can be in the above format with only the name All other docker images should be in the format -
    owner/docker-image-name So for this we will need to add the owner tag to the existing image that we want to push to docker hub.
    docker image tag employee-producer javainuse/employee-producer
    

    Docker Tag Image
    If we now list the docker images we see two docker images with same id.
    docker image ls 
    

    Docker Image list

  • Now we can push the image to docker hub as below-
    docker image push javainuse/employee-producer
    

    DockerHub Push Image employee producer

    DockerHub Push Image
    If we go to our DockerHub home page we can see that the image has been uploaded to DockerHub.
    DockerHub Image Upload
Similarly we will be pushing the employee-consumer image we had developed to dockerhub.

Download Source Code

Download it - Employee Consumer Docker Module
Download it - Employee Producer Docker Module