Tags docker registry ssl nginx
2021-02-15 15:30:35
Docker registry is an essential infrastructure of docker daemon or Kubernetes. We package project artifacts by docker image while storage and distribution by registry service. Today we will show you how we are setting up a straightforward and small registry implementation by docker official. It convenience a docking workflow for CI/CD.
Deploy structure:

docker run -d -p 5000:5000 --restart=always --name registry -v /data/registry:/var/lib/registry registry:2
docker run -d -p 5001:80 --name registry-ui -e DELETE_IMAGES=true joxit/docker-registry-ui:static
/data/registry to your own storage path-e DELETE_IMAGES=true intends docker images can delete through UI operation
Run the static interfacejoxit/docker-registry-ui:static docker file we can know:
cross region and registry_url and SSL config can be moved to our nginx deploy for more flexible and clean config management.Generally, we install nginx by Linux package management such as apt.
We can install nginx under ubuntu by the command sudo apt-get update && sudo apt-get install -y nginx
Then we install the following config file under your config dir. The default path is /etc/nginx/sites-enabled/
Here we storage the config file in /etc/nginx/sites-enabled/registry
server {
listen 443 ssl;
server_name [[REPLACE: YOUR OWN DOMAIN NAME]];
ssl_certificate /etc/ssl/[[REPLACE: YOUR DOMAIN SSL CRT FILE]];
ssl_certificate_key /etc/ssl/[[REPLACE: YOUR DOMAIN SSL KEY FILE]];
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
client_max_body_size 2048M;
location / {
proxy_pass http://127.0.0.1:5001;
}
location /v2 {
proxy_pass http://127.0.0.1:5000;
}
}
server{
listen 80;
server_name [[REPLACE: YOUR OWN DOMAIN NAME]];
return 301 https://$host$request_uri;
}
ATTENTION: please replace the config with your environment situation.
server_name must replace with your domain name.Let’s encrypt DNS-01 challenge to verify your domain and get an SSL cert file.ssl_certificate must replace with your domain crt file.ssl_certificate_key must replace with your domain key file.client_max_body_size at 2GB since we usually push a large docker image layer in practice.location / route to registry UI container.location /v2 route to registry service.HTTPS for your service since the docker daemon or kubelet needs other configs to trust your registry.server under the config file which helps us force switch from HTTP to HTTPSSAFETY WARNING:
Do not deploy this solution in the public network.