The Docker hub is an online place where Docker images are hosted publicly and other people can use those images. You can build your own Docker image and publish it to the DockerHub. Today we will learn to push our local docker images to the docker registry.

Prerequisite

Create an account in Dockerhub

  • Signup in Dockerhub and this will create an account for you
  • Once you log in to your account then you need to find your username
  • Click on the My Profile link
DockerHub Create your account

you can see your username pointed by the arrow

Build a docker image locally

we have an existing NodeJS project with dockerfile. You can create a docker image from it

Clone the repo locally and then go to that folder using your terminal.

git clone https://github.com/codewithrajranjan/Nodejs-application-with-docker

Build your docker image using the command below. you need to provide your username and the image name.

docker build -t <user-name>/<image-name> .

In my case, we are taking

  • user-name: selftuts
  • image-name: node-sample-app
docker build -t selftuts/node-sample-app .

This will build the image locally

Docker image build locally

You can check the image local using the below commands and see the image name as selftuts/node-sample-app

docker images
  Nodejs-application-with-docker git:(master)  docker images
REPOSITORY                    TAG       IMAGE ID       CREATED         SIZE
selftuts/node-sample-app      latest    c482425ff39d   2 minutes ago   65.2MB
<none>                        <none>    c5191809be90   7 days ago      65.8MB
alpine                        latest    042a816809aa   3 weeks ago     7.05MB
gcr.io/k8s-minikube/kicbase   v0.0.36   866c1fe4e3f2   3 months ago    1.11GB

CLI login to Dockerhub account

Now you need to login into your Dockerhub account from your terminal and you need to enter your credentials and then you will be successfully logged in

docker login

Push the image to the Docker hub

You need to use your image name to push it to Dockerhub. In this case, the image name is selftuts/node-sample-app

docker push selftuts/node-sample-app

once it is successfully pushed then you can check the image being listed in the Dockerhub account

References

Leave a Reply

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