WittCode💻

How to Set Up a Local Docker Registry

By

Learn how to set up a local Docker registry on your machine using the registry Docker image. We will also go over what a Docker registry is and why they are useful.

Table of Contents 📖

What is a Docker Registry?

A Docker registry is a location for storing and distributing images. They allow us to share Docker images with others. A popuplar registry is Docker Hub, a public registry that anyone can use.

INFO: Docker Hub is the default registry but there are many other registries available such as Amazong Elastic Container Registry (ECR) or Google Container Registry (GCR).

We can also run a local Docker registry on our machine, which is what we will do here.

Creating a Local Docker Registry

We can use Docker itself to create a local registry by spinning up a container from the registry image.

docker run -d -p 6500:5000 --restart=always --name registry registry:2

This runs a local container called registry on localhost port 6500. This container is made from the registry image version 2. The -d flag runs the container in the background.

INFO: Port 5000 is the default port number for the local registry. This is why we map the machine port to port 5000 in the container.

After running this command we will have a local registry running on port 6500. We can then push an image to the local registry and pull it from it. Lets pull the Nginx image and then push it to the local registry.

docker pulll nginx
docker tag nginx localhost:6500/my-nginx
docker push localhost:6500/my-nginx

Using default tag: latest
The push refers to repository [localhost:6500/my-nginx]
e4f01992bdae: Layer already exists 
951a8205e71f: Layer already exists 
3dd8d5238421: Layer already exists 
b7d730fe9ec2: Layer already exists 
e31648455514: Layer already exists 
9117941cac55: Layer already exists 
07d2ee3f5712: Layer already exists

Now lets remove these images from our computer and then pull it from the local registry.

docker rmi nginx
docker rmi localhost:6500/my-nginx
docker pull localhost:6500/my-nginx

Using default tag: latest
latest: Pulling from my-nginx
aa6fbc30c84e: Already exists 
168914bf900e: Already exists 
13b3fceec7e4: Already exists 
f9fa58e3da0f: Already exists 
00146e6e5257: Already exists 
50e4fc85b5d4: Already exists 
a408e3af440a: Already exists 
Digest: sha256:dae1b1a14984c8a2f73edc3d7d19345dddeeebc49a80baf7eafb226a5fc67525
Status: Downloaded newer image for localhost:6500/my-nginx:latest
localhost:6500/my-nginx:latest

ERROR: Removing the locally cached localhost:6500/my-nginx image does not remove it from the registry. That is why we can still pull it from the registry.

How to Set Up a Local Docker Registry