Hosting your Docker images in your own registry
One of the coolest things about Docker is that you already have a massive image repository out of the box: Docker Hub, where you can download and host your images publicly (and even privately for a fee).
But often Docker Hub just isn’t an option for you. This can happen when you don’t want your images leaving your local network, behind your firewall, or when you need to do a quick test.
For this reason the registry, which is the platform we use to store our images, has a major advantage that many don’t know about: it’s built as a Docker image itself.
Let’s learn how to create our own Docker Registry and store our images locally!
Hosting our own registry#
Besides solutions like Azure Container Registry, we can spin up our own Docker registry instance to keep enjoying the same experience we’re used to with Docker.
First, we need to run a local instance of the registry using the official image. We can do this with the following command:
docker run -d -p 5000:5000 --name docker-registry registry:2.7Keep in mind that the command above will only run the registry with ephemeral internal storage, meaning you’ll lose your images if you stop the container.
To run a persistent registry we can use the same command, but with the
-v seu/caminho:/var/lib/registryoption set before the image name.
From now on we can push any image to our local registry.
Working with images#
Naturally, when we create a registry that’s only accessible via localhost, like we’re doing here, there’s no reason to set a password. However, best practice is that if you’re creating a container accessible to people outside your local machine, always use a password and authentication with your registry.
We’ll learn how to do that authentication in another article, but for now let’s focus on how we can push our images. For this example, pick any image from the hub and download it to your machine with docker pull <image>, I’ll use the Debian image.
Every Docker image must be identified by its name so Docker knows which registry it refers to. This is done in the form of an FQDN: url.do.registry:porta/repositorio/imagem:tag.
In our case the registry is running locally on port 5000, the repository is like a group, so let’s create a group called official, and finally the image is Debian. So our image will be named:
localhost:5000/official/debian:latestLet’s tag our image with the docker tag command to change its name:
docker tag debian localhost:5000/official/debian:latestThe command won’t produce any output, but we’ll be able to see the image in docker image ls, and now we can push the image to the registry with docker push localhost:5000/official/debian:latest.
If we check the container logs with docker logs registry we’ll see that our registry received the image:

If we remove our local image with docker rmi localhost:5000/official/debian:latest, we can then use the docker pull command to fetch the image from our local registry and download it again:
docker pull localhost:5000/official/debianConclusion#
Using the registry is pretty straightforward. In the next articles we’ll explore how we can expand its use and make our registry even more secure!
This was a short article, but it shows a feature that few people know about how Docker works.
Don’t forget to follow me on social media for more content 😍