A Simple Docker Registry
In this article, I am going to explain how to create a simple private Docker registry. The utility of a private Docker registry is the ability to create & share images inside an organization without the necessity to push them to the cloud-based Docker hub. It will be faster as well as secure inside the organization. In this article, we are going to create the Docker registry in a Virtual Machine.
Software Used
Following is the set of software that will be used in this demo.
- Oracle Virtual Box
- Docker
- Docker-Compose
Docker Registry VM
Let’s create a very simple VM with CentOS 7. For Network Settings, I used Bridge Adapter.
If you prefer, you can opt for static IP. Check Create VM & Install GitLab section of the below article to assign static IP to a Virtual Machine.
Once created, do SSH into it and update it. In my case, the IP of the Docker Registry VM is 192.168.15.9
$ ssh -l root 192.168.15.9
$ sudo yum upgrade --assumeyes --tolerant
Disable SELinux
Navigate to the following file and open it in vi.
$ vi /etc/selinux/config
Save & exit. Then reboot the VM.
Install Docker & Docker Compose
Install docker and docker-compose in the VM. For docker-compose installation read the official documentation.
$ yum install docker
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
Then start and enable docker.
$ systemctl start docker
$ systemctl enable docker
At this point, we have installed docker and docker-compose in the Docker Registry VM.
Install a Cool Docker Registry
In the home folder (or whatever you wish) of the VM create a directory called registry. Inside that create a docker-compose.yml file. Inside the registry, create a directory named volume for mounting.
Below is the content of the docker-compose.yml
version: '3'
services:
docker-registry:
container_name: registry
image: registry:2
ports:
- 5000:5000
restart: always
volumes:
- ./volume:/var/lib/registry
docker-registry-ui:
container_name: registry-ui
image: konradkleine/docker-registry-frontend:v2
ports:
- 8080:80
environment:
ENV_DOCKER_REGISTRY_HOST: docker-registry
ENV_DOCKER_REGISTRY_PORT: 5000
Under the directory where docker-compose.yml is located, execute the following command.
$ docker-compose up -d
After successful execution, you should be able to navigate to the GUI of our private insecure docker registry at this URL: http://192.168.15.9:8080
Note that 192.168.15.9 is the IP address of the Docker Registry VM. The docker registry URL is 192.168.15.9:5000
Add Insecure Registry
Before pushing & pulling images to/from the registry, you will need to add the registry as an insecure registry in the machine from where you are going to access the registry. In macOS, you can add as shown below.
Then restart the Docker daemon.
Push & Pull Images
Tag an image with the Registry URL prefix:
$ docker tag apim 192.168.15.9:5000/apim
Push it:
$ docker push 192.168.15.9:5000/apim
Once the Image is pushed, you can view it in the GUI.
Conclusion
In this article, I have demonstrated how to install a very simple Docker registry for hosting images in a private environment. I didn't use HTTPS for this demo. You can install SSL certificates in the Docker registry for hardening.
Thanks for reading!