Hi everyone,
In this post, I try to show you how to push and pull docker image from DockerHub. I assume that you have some knowledge about docker and docker hub. If not ,don't worry keep going reading. First of all, we need to have an DockerHub account. If you don't have you can join with DockerHub website. After that you need to install docker
to your environment. You can find more information here how to install docker to your environment. I will use docker
command line interface when try to show you the demo that I created.
The detailed video available in YouTube.
This is our roadmap,
Push Image
First of all, we will create a repository in DockerHub
that name is docker-demo
. Make public the repository. I have created a repository like below.
After creating a repository in DockerHub
, we need to have an application that run on the web environment. We will create its image and will push them to DockerHub
. I will use my sample demo application. You can find it on my github profile.
You can install the sample application to your system. After that you need to create a fat jar with maven
. It is easy, just type below command.
mvn clean install
You will see the <your-app>.jar
file in your target folder when it's done.
The Dockerfile is below.
FROM openjdk:8
ADD ./target/*.jar /usr/src/my-sample-app.jar
WORKDIR usr/src
ENTRYPOINT ["java","-jar", "my-sample-app.jar"]
After doing this setup, everything is easy for us. I will just build docker image with docker command. Just type below command to build your application image.
docker build -t docker-demo .
After build docker image, we need to tag our image. You can use tag
command like below.
docker tag <Image ID> coderkan/docker-demo
Pushing your image to DockerHub
is easy after tagged image. You can type push
command like below.
docker push coderkan/docker-demo
You will just wait when uploading image to repository. You will see the uploaded image like below image.
After uploading your image to DockerHub
, you will see immediately your image in the repository.
Pull Image
Pulling an image from DockerHub
is easy. First of all, you need to go to your profile and get the repository name. I got the name docker-demo
. Then you just type below command to your terminal to get latest image from DockerHub
.
docker pull coderkan/docker-demo:latest
You can see the installed images with docker images
. You will see the details like below.
Running Application
You need to run this installed image with run
command.
docker run -p 8080:8080 coderkan/docker-demo
You will see the Started DockerDemoApplication in xxx seconds.
. This means that your application is started successfully. Now, you can check if the application is running or not with Browser
.
I hope this post help you to usage of pull or push images to DockerHub
.
I hope you enjoy while reading.
Have a nice coding.