How To Setup a Private Docker Registry on Ubuntu 22.04 / 20.04

How To Setup a Private Docker Registry on Ubuntu 22.04 / 20.04. In this post, we introduce the Docker registry, and its advantages and then explain how to set up a private Docker registry on Ubuntu.

Docker is one of the popular tools used for containerization in the realm of software development and deployment. With the help of these tools, developers package an application along with all of its dependencies into a single unit and easily execute software in one place. It further eases the process of moving it between various environments. There is a good possibility that you also use a Docker registry if you deploy applications inside of containers.

A Docker registry is a system that helps developers easily store, manage, and distribute containerized applications securely. Even users easily search and download them. In this blog, we discuss the docker registry in detail. Further, we point out how it benefits the developers in the software development and deployment process.

Shall we start with How To Setup a Private Docker Registry on Ubuntu 22.04 / 20.04

What is a Docker Registry?

All in all, a Docker Registry is an open source central repository that provides a scalable way to store and manage Docker images. In fact, anyone can install the software, create their own container image registry, and use it. Additionally, it is also used to host or distribute container images across different environments.

What is more, developers are able to upload, download, and send images to and from the Docker Registry. In return, it guarantees that everyone on the development team is using the same copy of the application and serves as a single point of truth for the entire group or development team.

Basically, Docker Registry is a crucial tool for software development and deployment because it offers a secure, scalable, and reliable way to store and control Docker images. Additionally, the exceptional features supported by these registries help developers in meeting their container requirements.

There are two types of Docker registries – Public Docker Registry and Private Docker Registry.

  1. A public Docker Registry is accessed by everyone and Docker Hub is one of the best examples of a public Docker Registry. Using the Docker Hub, developers securely store, manage, as well as distribute Docker images across different environments.

2. A private Docker Registry, on the other hand, is accessed only by authorized users. These types of docker registries are mostly used in enterprise environments where security and accountability are top priorities. Further, it is hosted on premises or on the cloud.

One of the most widely used Docker repositories is Docker Hub, which is used alongside Quay, Google Container Registry, JFrog Container Registry, and others.

Advantages of Docker Registry

  • Helps Store Container Images – Without having to handle numerous images spread across various repositories, businesses efficiently monitor container images with its centralized storage feature.
  • Better security – By ensuring that only authorized users view Docker images, private Docker registries add an extra layer of security.
  • A central repository for users to discover container images – Whether you are an employee, external customer, or both, Docker Registry allows its users to easily access the container images from a central location, search and download as per their need.
  • Enhanced Dependability – The development process is more reliable because the Docker Registry makes sure that everyone on the team is using the same version of the application.
  • Access controls – To make it easier for teams or developers to control who has access to which container image, most registries offer access control features. For example, in most cases, you give access to the general public to download some images while restricting access to other images to a selected group of authorized users.
  • Image versioning – When downloading images from the Docker Registry or running them through Docker, Kubernetes, or other tools, users have the option to specify a version o an app.
  • Improved Collaboration – Another benefit of using Docker Registry is it allows developers to exchange Docker images with other team members and facilitate project collaboration.

How To Setup a Private Docker Registry on Ubuntu 22.04 / 20.04

In this section, we show you steps how to set up a private Docker registry on Ubuntu.


  • A server running Ubuntu 20.04 or 22.04.
  • A root user or a user with sudo privileges.

Install Docker and Docker Compose

By default, the latest version of the Docker package is not included in the Ubuntu default repository. So you need to install it from Docker’s official repository.

First, install all the required dependencies using the following command.

					apt install apt-transport-https ca-certificates curl software-properties-common -y

Next, download and import the Docker GPG key with the following command.

					curl -fsSL | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Then, add the Docker repository to the APT using the following command.

					echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null


Next, update the repository cache and install Docker with the following command.

					apt update
apt install docker-ce docker-compose -y

Once both packages are installed, please verify the Docker installation using the following command.

					docker info

You should see the following screen.

Create Docker Compose File for Docker Registry

Firstly, create a project directory to setup a private Docker registry.

					mkdir project

Next, navigate to the project directory and create a registry data directory.

					cd project
mkdir registry-data

Then, create a docker-compose.yml file.

					nano docker-compose.yml

Define your port, auth parameters, volumes and data directory as shown below.

					version: '3'

restart: always
image: registry:latest
- "5000:5000"
REGISTRY_AUTH_HTPASSWD_PATH: /auth/registry.password
- ./auth:/auth
- ./registry-data:/registry-data


Save and close the file when you are finished.

Install and Configure Nginx for Docker Registry

By default, Docker Registry can not be accessed from the remote machine. You need to configure Nginx as a reverse proxy for Docker Registry.

First, install the Nginx and other required packages with the following command.

					apt install nginx apache2-utils -y

Once the Nginx server is installed, create an Nginx virtual host configuration file for the Docker registry.

					nano /etc/nginx/conf.d/registry.conf

Add the following configurations.

					server {
listen 80;

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

location / {
# Do not allow connections from docker 1.5 and earlier
# docker pre-1.6.0 did not properly set the user agent on ping, catch "Go *" user agents
if ($http_user_agent ~ "^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*$" ) {
return 404;

proxy_pass http://localhost:5000;
proxy_set_header Host $http_host; # required for docker client's sake
proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 900;


Save and close the file then edit the Nginx main configuration file and increase the max upload file limit.

					nano /etc/nginx/nginx.conf

Add the following line after the line http {:

					client_max_body_size 20000m;

Save and close the file then restart the Nginx service to apply the changes.

					systemctl restart nginx

Next, you need to create a auth directory and create a auth password to enable the password authentication on Docker Registry. First, create a auth directory with the following command.

					mkdir project/auth

Then, create an admin user with the following command.

					cd project/auth
htpasswd -Bc registry.password admin

Set an admin password as shown below.

Start the Docker Registry Container

At this point, everything is configured properly. Now, it’s time to start the Docker Registry container. Navigate to your project directory and start the Docker Registry container with the following command.

					cd project
docker compose up -d

You should see the following screen.

Now, verify the Docker Registry container using the following command.

					docker-compose ps

You should see the status of the running container on the following screen.

Create a Custome Image and Publish on Docker Registry

First, download the Ubuntu image and run it with the following command.

					docker run -t -i ubuntu /bin/bash

You get into the Ubuntu shell.

download and run ubuntu image

Next, create some directories using the following command.

					mkdir test1 test2

Then, exit from the Ubuntu container with the following command.


After, create a new image from the Ubuntu container.

					docker commit $(docker ps -lq) ubuntu-image

Get the following output.


Log in to your private Docker Registry with the following command.

					docker login

Provide your admin username and password to login to the registry. You should see the following screen.

Following, rename your created image with the following command.

					docker tag ubuntu-image

Finally, upload your newly created image to the private Docker Registry using the following command.

					docker push

If everything is fine, you should see the following screen.

Download the Image From a Private Docker Registry.

At this point, your private Docker Registry is installed and configured. Now download your uploaded Ubuntu images on any machine.

Now, go to the remote machine, log into your Docker Registry with the following command.

					docker login

Here, at this step, download the Ubuntu image with the following command.

					docker pull

Once the image is downloaded, you should see the following screen.

Now run the container from the downloaded image using the following command.

					docker run -it /bin/bash

Now, verify your test directories using the following command.


You should see both test directories on the following command.

Thank you for reading How To Setup a Private Docker Registry on Ubuntu 22.04 / 20.04. We shall conclude this article blog now. 

How To Setup a Private Docker Registry on Ubuntu 22.04 / 20.04 Conclusion

Well, with the help of Docker Registry, developers easily store and manage their Docker images. In addition, it provides a secure and scalable way to manage Docker images and distribute them across different environments, such as development, staging, as well as production.

No doubt, Docker Registry works as a great tool for modern software development and deployment process. Whether you are planning to work on a small project or on a large enterprise application, Docker Registry, quickly streamlines your process and enhance collaboration.

Do explore more of our docker content by navigating in our blog over here

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x