# Push & Pull Image to Docker Hub

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](https://hub.docker.com/) website. After that you need to install `docker` to your environment. You can find more information [here](https://docs.docker.com/engine/install/) 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.

%[https://youtu.be/03G2Sybyr6I]

This is our roadmap,

  - [**Push Image**](#push-image)
  - [**Pull Image**](#pull-image)
  - [**Running Application**](#running-application)


## 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.


![Docker Hub Registry](https://cdn.hashnode.com/res/hashnode/image/upload/v1613316030789/_VofF5IMD.png)


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](https://github.com/coderkan/blog-samples/tree/main/spring/docker-demo) profile.

%[https://github.com/coderkan/blog-samples/tree/main/spring/docker-demo]


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.


```shell
mvn clean install
```

You will see the `<your-app>.jar` file in your target folder when it's done.

The Dockerfile is below.

```shell
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.

```shell
docker build -t docker-demo .
```


![docker-build.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613326200384/4lnnAXnfh.png)


![docker-images.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613326738653/My9Ncin9q.png)

After build docker image, we need to tag our image. You can use ` tag` command like below.

```shell
docker tag <Image ID> coderkan/docker-demo
```

![docker-tag.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613326926514/90NhmBgQz.png)

Pushing your image to `DockerHub` is easy after tagged image. You can type `push` command like below.

```shell
docker push coderkan/docker-demo
```

You will just wait when uploading image to repository. You will see the uploaded image like below image.

![docker-push.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613327056606/BSMoSUm9Z.png)

After uploading your image to `DockerHub`, you will see immediately your image in the repository. 


![docker-hub-uploaded.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613327251608/Quo2k6afz.png)


## 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`.

```shell
docker pull coderkan/docker-demo:latest
```

You can see the installed images with `docker images`. You will see the details like below.

![docker-pull.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613328018000/GB3NNSAyL.png)


## Running Application

You need to run this installed image with `run` command. 

```shell
 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`.

![docker-run.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613328337026/vNwCLAJ1i.png)

![hello-world.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1613328353976/eCs_tj272.png)

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.

<span>Photo by <a href="https://unsplash.com/@kylry?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kyle  Ryan</a> on <a href="https://unsplash.com/s/photos/container?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>


%%[youtube-widget]






