Open In App
Related Articles

Docker – Using Public Repositories To Host Docker Images

Like Article
Save Article
Report issue

Pre-requisites: Docker

Docker is a software platform for creating isolated virtualized environments for building, deploying, and testing applications with ease. In this tutorial, we will learn how to host public repositories on docker hub which is a hosted repository service provided by Docker for finding and sharing container images. Just like GitHub allows the hosting of code of our application, DockerHub allows the hosting of Images of our applications.

Docker Image

In order to run these applications, we first need to create an image of the current application state. An image can be sometimes referred to as a snapshot of our project. Images are read-only in nature and consist of file that contains the source code, libraries, dependencies, tools, and other files needed for an application to run.

 A Docker image is a read-only template that contains a set of instructions for creating a container which can run on the Docker platform.

Docker Registry

A Docker registry is a service that stores and manages Docker images. Docker registry could be hosted by a third party, as a public or private registry. Some examples of Docker registries are as follows:

Docker Repository

A Docker repository is a collection of different Docker images with the same name, that have different tags. Tags basically are identifiers of the image within a repository.

In this tutorial, we will use Docker Hub to host our repositories, which is free for public use.


Step 1. Creating An Account On Docker Hub. Go to DockerHub and create a new account or log in to your existing account.

Docker Hub


Step 2. Creating  A Repository (optional)

On the docker hub, you can create a repository by clicking on create repository button. Give the repository a name and description and make sure it is marked as public. This step is not necessary when you are hosting a public repository. It is used while hosting a private one.

Docker Repository


Repository Name image widget.

Docker Push Command


Step 3. Build a Docker Image

Now we will generate a basic express application and create an Image out of it.

$ mkdir express-app && cd express-app
$ npx express-generator -e
Docker build Image


Now, create a Dockerfile for the application and copy the content as shown below:

$ touch Dockerfile
FROM node:16

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json 
# AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .


CMD [ "npm", "start" ]


You can now build this Dockerfile with the docker build command.

$ docker build -t rhythmshandlya/express-app .
Docker Build


One thing to notice is as did not specify the tag name, it will be given the : latest tag.

Step 4. Run This Image Locally

$ docker run -p 3000:3000 rhythmshandlya/express-app
Port Mapping


Step 5. Push Image to docker hub. To push a local Image to the docker hub we will need to log in to the docker hub with our terminal.

$ docker login
Docker Login


$ docker push rhythmshandlya/express-app
Docker Push


Pushed image in DockerHub


Step 6. Playing With Tags. We can make changes to this application and give it a version tag of 0.0.1

$ docker build -t rhythmshandlya/express-app:0.0.1 .
$  docker push rhythmshandlya/express-app:0.0.1


Images with tags pushed


Now that we have hosted our image in public anyone can pull and run them on their machines.

$ docker pull rhythmshandlya/express-app:latest 
$ docker push rhythmshandlya/express-app:0.0.1

Lost in the complex landscape of DevOps? It's time to find your way! Enroll in our DevOps Engineering Planning to Production Live Course and set out on an exhilarating expedition to conquer DevOps methodologies with precision and timeliness.
What We Offer:

  • Comprehensive DevOps Curriculum
  • Expert Guidance for Streamlined Learning
  • Hands-on Experience with Real-world Scenarios
  • Proven Track Record with 100,000+ Successful DevOps Enthusiasts

Last Updated : 25 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Similar Reads
Complete Tutorials