Pre-requisites: Docker, Docker HUB
Docker registry is your own private repository where you can store your own Docker images and share them with others. Docker Registry is basically organized into Docker Repositories. Within the docker Repository, you can maintain specific versions of a Docker Image.
What is Docker Registry?
Docker registry is your own private repository where you can store your own Docker images and share them with others. Docker Registry is basically organized into Docker Repositories. Within the docker Repository, you can maintain specific versions of a Docker Image. DockerHub is the public repository for pulling docker images. DockerHub is a public repository where anyone can pull the images which are stored in DockerHub.
Public and Private Docker Registries
The two types of repositories offered by Docker Hub are public and private. Since the majority of our Docker images contain source code and all the dependencies necessary for our application, the public repository is accessible to anyone who works on Docker images that we store in the Docker Hub public registry, which is bad for businesses. Therefore, Docker Hub offers a paid private repository; but, because cloud storage is expensive, numerous images cannot be stored there.
We can create a free, personal Docker registry on a local computer. We may adjust the authentication, balance the load, and make other configuration adjustments using a private registry. Here, we can keep our images in a private place.
Steps To Setup Private Docker Registry
Follow the below steps to setup the docker registry:
Run a Private Docker Registry
Step 1: Pull the Docker registry image using the below request:
$ docker pull registry
This command will pull the docker latest image from the docker registry
Step 2: Configure and run the docker registry image using the below command:
$ docker run -d -p 5000:5000 --name localregistry registry
This command will start the docker container registry on localhost port 5000. The base image used is the registry. The local registry will be the container name.
Now we will also look into how you can pull, push and delete images from the local registry container. When the local registry container is pushed successfully, it will return the container ID in the console.
You can verify by running the below command:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
25a66bd4219f registry “/entrypoint.sh /etc…” 10 seconds ago Up 9 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp localregistry
Step 3: Pull images from DockerHub.
Let’s try to pull some images from DockerHub and push them to your docker private registry. For demonstration, let’s one version of the Ubuntu image and the latest Nginx server image.
Push an Image to the Private Registry
Step 1: Tag the images which were pulled from DockerHub.
- localhost:5000 -> host for your docker private registry
- ubuntu: repository name
- 18.04: tag to identify the version
Step 2: Push the tagged images to your docker private registry.
Push an Image to the Private Registry
Step 1: Pull the docker nginx image from the private docker registry. We are here pulling the docker image of Nginx: latest hosted at private registry i.e at localhost:5000