push docker image to docker hub

A Docker hub is an online place where Docker images are hosted publicly and other people can use those images in their Projects. You need to create a docker image and then push that to Docker Hub

Prerequisite

  • You should install Docker on your machine
  • You need to have an account on Dockerhub

Create Your 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

you can see your username pointed by the arrow

Build Docker image locally

  • we have an existing NodeJS project with Dockerfile.
  • You can create a docker image from it
  • Project Link
  • Clone the repo to your local machine and then go to that folder using your terminal.
  • Build your docker image using the command below.
  • Note: You need to provide your username and image name.
docker build -t <user-name>/<image-namge> .
  • In this case, we are taking
  • user-name = selftuts
  • image-name = node-sample-app

The final command which you will use to build the Docker image is

docker build -t selftuts/node-sample-app .

This will build the image locally

you can check the image in your local machine 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
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

Login to Docker Hub account using the Command Line Tool

You need to Login into your DockerHub account using the Command line tool

docker login

You will be asked to enter your credentials like username and password.

Push Docker Image to 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

Next: Install Docker on Ubuntu22.x

Leave a Reply

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