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
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.
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.
Offers Easy distribution of Docker images – With Docker Registry, developers easily distribute the Docker images across development, staging, and production environments.
Helps Store Container Images – Without having to handle numerous images spread across various repositories, businesses efficiently monitorcontainer 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 projectcollaboration.
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.
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;
server_name registry.example.com;
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
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.
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.
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.