momo's Blog.

docker registry 部署

字数统计: 241阅读时长: 1 min
2023/02/13 Share

前言

临时需要部署docker仓库,这里记录一下命令行 主要参考: 官方文档

部署

配置账号密码

1
2
3
4
5
mkdir -p /data/registry/http-auth
cd /data/registry/http-auth/

# 生成http user
docker run --entrypoint htpasswd httpd:2 -Bbn root password > htpasswd

配置 SSL

自签证书

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
mkdir -p /opt/ssl/
cd /opt/ssl/
# openssl 小于 1.1.0
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
-keyout key.pem -out cert.pem -extensions san -config \
<(echo "[req]";
echo distinguished_name=req;
echo "[san]";
echo subjectAltName=DNS:localhost,IP:10.236.0.115
) \
-subj "/CN=localhost"


# openssl ≥ 1.1.1
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
-keyout key.pem -out cert.pem -subj "/CN=localhost" \
-addext "subjectAltName=DNS:localhost,DNS:www.example.net,IP:10.236.0.115"
  • Linux:
    • mkdir -p /etc/docker/certs.d/10.236.0.115:4433/
    • cp /opt/ssl/cert.pem /etc/docker/certs.d/10.236.0.115:4433/ca.crt

启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
docker run -d \
-p 5000:5000 \
--restart=always \
--name registry \
-v /data/registry:/var/lib/registry \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
-v /data/registry/http-auth/:/auth \
-v /opt/ssl:/certs \
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/cert.pem \
-e REGISTRY_HTTP_TLS_KEY=/certs/key.pem \
-p 4433:443 \
registry:2
CATALOG
  1. 1. 前言
  2. 2. 部署
    1. 2.1. 配置账号密码
    2. 2.2. 配置 SSL
      1. 2.2.1. 自签证书
    3. 2.3. 启动