What is Docker Registry?

  • The Registry is a stateless, highly scalable server-side application.
  • It allows you to locally store all your Docker images in one centralized location.
  • Docker registry is a repository of Docker images from where you can pull and push images.
  • The registry holds different tagged versions of images.
  • Own private Docker images storage that can be hosted in your data center.
  • Running your own Registry is a great solution to integrate with and complement your CI/CD system.

Setting up a private Docker registry

The Docker registry is just a Docker image! So, in order to set up a Docker registry, you first need to… set up Docker itself so docker needs to install on your system.

Use the following command, to start the registry container:

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

An explanation of this command is as below,

  • docker run — Create a docker container
  • -d option is used to run a container in the background and print container ID.
  • — restart=always, Always restart the container if it stops.
  • -p option is used for port mapping between container and Host machine.
  • — name option is used to assign a name to the container.
  • In the end, we provide the name of the docker image (registry:2) from which we wish to run our container.

The registry is now ready to use and let’s test the Private Registry

In order to test this setup, we can pull an image from Docker Hub and push it to your registry.

  1. Pull the ubuntu:16.04 image from Docker Hub.
$ docker pull ubuntu:16.04

2. Tag the image as localhost:5000/my-ubuntu

$ docker tag ubuntu:16.04 localhost:5000/my-ubuntu

3. Push the image to the local registry running at localhost:5000

$  docker push localhost:5000/my-ubuntu

4. Remove the locally-cached ubuntu:16.04 and localhost:5000/my-ubuntu images, so that you can test pulling the image from your registry. This does not remove the localhost:5000/my-ubuntu image from your registry.

$ docker image remove ubuntu:16.04
$ docker image remove localhost:5000/my-ubuntu

5. Pull the localhost:5000/my-ubuntu image from your local registry.

$ docker pull localhost:5000/my-ubuntu

Cloud and DevOps Enthusiast