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

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 – https://hub.docker.com/, We can login here and create an account.

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

 

 

pom.xml

AppController.java

App.java

Dockerfile

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.

Example:

docker image tag “imageId” sriis1987/helloworld:v1

docker image push sriis1987/helloworld:v1

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

NOTE:

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

docker login

This is request for username and password of docker hub.

 

Leave a Reply

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