Docker Hub – Push and Pull Images – Deploy as Container with Example

In our previous article, We learnt how to Dockerize SpringBoot Application with Simple Hello World example.  In this post, let us see how can we push the image to docker hub and how can we pull it and deploy the application as docker container.

So for pushing and pulling the image from Docker Hub, first we need to create an account in Docker hub.

Docker Hub –, We can login here and create an account.

We are going to use the same example used in our previous article,




<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""
		<relativePath /> <!-- lookup parent from repository -->
	<description>SpringBoot with Docker - Dockerizing</description>





package com.javainfinite;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

public class AppController {
	public String display() {
		return "Hello World!!!";


package com.javainfinite;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class App {

	public static void main(String[] args) {, args);



FROM openjdk:8
EXPOSE 8086:8080
MAINTAINER javainfinite
WORKDIR /usr/local/bin
COPY ./target/SpringBoot_Docker-0.0.1-SNAPSHOT.jar HelloWorld.jar
ENTRYPOINT ["java", "-jar", "HelloWorld.jar"]

First let us create an image from the above docker file,

docker image build -t “sampleImage” .

In this example let us use image name as helloworld,

docker image build -t “helloworld” .

The above command will generate the image and can be seen with command,

docker images

We have successfully build the image, So in order to push the image to docker hub. First we need to tag it,

docker image tag “imageid” dockerhub username/repository

For this example, My dockerhub account is sriis1987,

docker image tag 09b9013b2982 sriis1987/helloworld

This will tag the image name, you can see it with docker images.

Then we need to push it,

docker image push dockerhubid/repository

For this example,

docker image push sriis1987/helloworld

Now in our docker hub account, we can see the image been successfully pushed.


When clicking this repository, we can see our pull command too (public view),

Now we can pull this image and we can deploy the container using imageid.

docker container run imageid.

Suppose if we update the same application, do we have to create new repository?

No, We dont have to.

Suppose if you update the existing file and you can push the image to same repository. It will just update the same image.


docker image tag “imageId” sriis1987/helloworld:v1

docker image push sriis1987/helloworld:v1

The above command will update the repository with the new image.


Suppose if it shows cannot authenticate or need to authenticate use command,

docker login

This is request for username and password of docker hub.


By Sri

Leave a Reply

Your email address will not be published. Required fields are marked *