生成私有ssl证书1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23mkdir -p ~/registry/certs
cd ~/registry/certs
openssl genrsa -out registry.wting.com.key 1024
openssl req -newkey rsa:4096 -nodes -sha256 -keyout registry.wting.com.key -x509 -days 365 -out registry.wting.com.crt
Generating a 4096 bit RSA private key
.........................++
.....................................................................................................................++
writing new private key to 'registry.wting.com.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:cn //← 国家代号
State or Province Name (full name) [Some-State]:sc \\← 省的全名
Locality Name (eg, city) []:cd \\ ← 市的全名
Organization Name (eg, company) [Internet Widgits Pty Ltd]:wt \\公司英文
Organizational Unit Name (eg, section) []:it \\
Common Name (e.g. server FQDN or YOUR name) []:it \\
Email Address []:123@123.com //← 电子邮箱
1 | docker pull registry:2 |
Push到Registry:1
2
3
4
5
6
7
8docker push registry.wting.com/nginx:test
The push refers to a repository [registry.wting.com/nginx] (len: 1)
unable to ping registry endpoint https://registry.wting.com/v0/
v2 ping attempt failed with error: Get https://registry.wting.com/v2/: x509: certificate is valid for it, not registry.wting.com
v1 ping attempt failed with error: Get https://registry.wting.com/v1/_ping: x509: certificate is valid for it, not registry.wting.com
push失败了!docker client认为server传输过来的证书的签署方是一个unknown authority(未知的CA),因此验证失败。我们需要让docker client安装我们的CA证书:
sudo mkdir -p /etc/docker/certs.d/registry.wting.com
sudo cp registry.wting.com.crt /etc/docker/certs.d/registry.wting.com/ca.crt
重启Docker Daemon
认证方式1
2
3
4
5
6
7
8
9
10
11
12cd ~/registry/
mkdir auth
docker run --entrypoint htpasswd registry:2.2 -Bbn docker 1233 > auth/htpasswd;
ocker run -d -p 443:5000 --restart=always --name registry \
-v `pwd`/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
-v /home/docker/registry/certs:/certs \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.wting.com.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/registry.wting.com.key \
registry:2
登录1
2docker login registry.wting.com
----