Docker Registry

Introduce

The Docker registry is where images are stored during container startup. Most people are using existing images and if you don't know, it is hosted at the official Docker hub. However, there are some limitations when using docker hub as follows:

– Server located abroad (different from Vietnam)

– Charge for private images. You cannot publicize internal images, so you only have to choose private images. If you have a few projects, the cost is not high. But if you develop in a microservice direction, there will be a few dozen to a few hundred private images. If you rent in a package, it is completely uneconomical.

With the above two limitations, most companies deploy their own registry because the registry is also open source. You rent/buy a server, vps and start the image registry 2.0 and you're done, and there are many instructions online showing you how to build such a private registry. However, the registry you built is almost impractical and is only for testing. The content of this article is aimed at a production registry installation that means real running, not for testing, which requires a number of requirements such as a private, short domain name, https support, backup and ACL (Access Control) support. List).

Introducing some Docker Registry services

We will evaluate a number of registry service providers. Here I will talk about the main features and overview of the services based on the following criteria.

  • Workflow (build/deploy, collaboration, ease of use, and visibility)

  • Authentication and authorization

  • Availability and performance

  • Expense

Docker Hub

Working process:

  • Integration with Github and BitBucket

  • Familiar model like Github

  • Repository link, for automatic builds

  • Full documentation, easy to use

Authentication and authorization:

  • Organizations can be created

  • Lack of access control for each user

  • Lacks support for external authentication providers, for example LDAP, SAML and OAuth

Availability and performance:

  • Stable performance

price:

  • Cheap and independent use

Quay.io

Working process:

  • The interface is easy to use, intuitive and streamlined

  • Automatic build

  • There are announcements about events

Authentication and authorization:

  • Ability to create organizations and teams

  • Pass-through access control

  • Only supports authentication via OAuth

Availability and performance:

  • No support

price:

  • Relatively inexpensive and self-contained

Artifactory

Working process:

  • All in one

  • Easy for beginners to use

Authentication and authorization:

  • Comprehensive authentication capabilities

Availability and performance:

  • Remote repository cho HA

price:

  • High cost

Google Container Registry

Working process:

  • Not compatible with Docker client

  • Little support for integration with build and deployment

Authentication and authorization:

  • Control access with GCS ACL

  • Enhanced security through short-term token auth

  • Supports LDAP synchronization

Performance and availability:

  • Use available HA of Google cloud storage

price:

  • Low cost

Deploy Docker Registry

1. Domain name and SSL Certificate for Docker Registry

Domain

You need to choose a domain name for your registry. You can buy a domain name and create an A record to return to the IP of your VPS/Server. For example, I chose the domain name infra.framgia.vn as my registry.

SSL Certificate

Because the private registry supports https by default, you need to have an SSL Certificate for your domain. You can buy SSL from an SSL service provider such as GeoTrust, RapidSSL, Verisign... Here I use a free SSL service called letsencypt . How to create a cert is very simple, just download the script and run it.

After creating SSL, it will be saved in the following path

Here is the certificate I generated:

As shown above, you will use the fullchain1.pem and privkey1.pem bundle files to be able to configure https.

To facilitate the steps to run containers, rename the bundle crt file to “cert.pem” file and the .key file to “key.pem”. Proceed to the step of initializing the private registry.

2. Installation

To set up security for the Docker Registry it is best to use Docker Compose. This way we can easily run Docker Registry on a container and let Nginx handle and communicate with the outside world. Install docker-compose:

Because we will use Nginx for authentication, to store the list of usernames and passwords we want to access the registry. We will install the apache2-utils package which contains htpasswd utilities that can easily generate basic authenticate:

First create a directory where the files will be stored:

Create docker-compose.yml file as follows:

nginx:

Nginx container

image : image nginx 1.9

ports : Nginx container port 443 will map to port 443 of the host machine.

links : When Nginx container runs, it will link to the registry container with the hostname being the registry and regardless of the IP of the registry container. Actually, Docker has inserted /etc/hosts in the nginx container hostname of the container registry.

volumes : stores nginx config files on the host computer, the /etc/nginx/conf.d/ folder on the container will be mounted into the ~/docker-registry/nginx directory on the host machine.

Create a registry.conf file with the following content:

Create a registry.password file containing registry login information

Finally, Copy SSL certifcate, you will have a directory tree like this:

Screenshot at Oct 24 17-29-25.png

Registry container

image : registry version 2

port : Registry container port 5000 will map to port 5000 of the host machine and only listen on localhost (127.0.0.1)

environment : env on the Docker registry container is set to /data. Docker registry will check environment variables on startup and store data here.

3. Use private registry from client

Add certificate to client. You will copy the content of the cert.pem file and then add it to the client depending on the OS.

Mac OS X

Windows

Linux (Free, Debian)

Linux (CentOs 6)

Linux (CentOs 5)

Test by pushing and pulling images

Publish image tới docker registry

Pull image from docker registry

Last updated