Self hosted Docker registry

Self hosted Docker registry

When using the docker pull command, container images are by default downloaded from docker hub, the official public registry for container images. However, for some projects, images are better stored on a private platform. This can be achieved by hosting one's own docker registry.

A complete guide is written here: https://docs.docker.com/registry/deploying/

This article merely summarizes the basics involved in the process.

Self hosted Docker registry as container

A docker registry is an application juste like any other and can this be containerized. In fact, an official image is available on docker hub. It can be run as so:

docker run -d --restart=always --name registry -p 5000:5000 -e REGISTRY_HTTP_ADDR=0.0.0.0:5000 registry:2

Pushing to the registry

To push images to a specific registry, their name must be in the form <registryUrl>/<imageName>. A new name can be set to an image using the docker tag command:

docker tag my-local-image:version 192.168.1.2:5000/my-image

Here, replace 192.168.1.2 with the URL of your registry

Image can now be pushed to the registry using the docker push command

docker push 192.168.1.2:5000/my-image