[root@guiqiu-virtualbox~]# curl http://registry.com.cn:5000/v2/
{}[root@guiqiu-virtualbox~]# curl http://registry.com.cn:443/v2/
<html>
<head><title>400
The plain HTTP request was sent to HTTPS port</title></head>
<body
bgcolor="white">
<center><h1>400
Bad Request</h1></center>
<center>The
plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.9.15</center>
</body>
</html>
[root@guiqiu-virtualbox~]#
加上密码再试下
[root@guiqiu-virtualbox~]# curl http://docker:214040@registry.com.cn:443/v2/
<html>
<head><title>400
The plain HTTP request was sent to HTTPS port</title></head>
<body
bgcolor="white">
<center><h1>400
Bad Request</h1></center>
<center>The
plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.9.15</center>
</body>
</html>
[root@guiqiu-virtualbox~]#
加入SSL验证
$ openssl req -new -key domain.key -out dev-docker-registry.com.csr
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 adefault value, If you enter '.', the field will be left blank.
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg,city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:registry.com.cn
Email Address []:
Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:
An optional company name []:
签署认证请求
执行docker-compose up
-d在后台运行Registry,并使用curl验证结果。这时使用localhost:5000端口仍然可以直接访问Registry,但是如果使用443端口通过nginx代理访问,因为已经加了SSL认证,所以使用http将返回“400
bad request”
$ curl http://localhost:5000/v2/
{}
$ curl http://localhost:443/v2/
<html>
<head><title>400
The plain HTTP request was sent to HTTPS port</title></head>
<body
bgcolor="white">
<center><h1>400
Bad Request</h1></center>
<center>The
plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.9.9</center>
</body>
</html>
应该使用https协议
$ curl https://localhost:443/v2/
curl: (60) Peer
certificate cannot be authenticated with known CA certificates
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL
certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA
certs). If the default
bundle file isn't adequate, you can specify an
alternate file
using the --cacert option.
If this HTTPS server
uses a certificate signed by a CA represented in
the bundle, the certificate verification
probably failed due to a
problem with the certificate (it might be
expired, or the name might
not match the domain name in the URL).
If you'd like to turn
off curl's verification of the certificate, use
the -k (or --insecure) option.
由于是使用的未经任何认证机构认证的证书,并且还没有在本地应用自己生成的证书。所以此时会提示使用的是未经认证的证书,可以使用“-k"选项不进行验证。
#查看本地已有镜像
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2 cd57aad0bd45 3 days ago 224.5 MB
nginx 1.9 813e3731b203 3 weeks ago 133.9 MB#为本地镜像打标签
$ docker tag
registry:2 docker-registry.com/registry:2
$ docker tag
nginx:1.9 docker-registry.com/nginx:1.9
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2 cd57aad0bd45 3 days ago 224.5 MB
docker-registry.com/registry 2 cd57aad0bd45 3 days ago 224.5 MB
nginx 1.9 813e3731b203 3 weeks ago 133.9 MB
docker-registry.com/nginx 1.9 813e3731b203 3 weeks ago 133.9 MBpush测试
#不登陆直接push镜像到registry,会提示失败
[root@PRO-REGISTRY-220
~]# docker push docker-registry.com/registry:2
The push refers to a
repository [docker-registry.com/registry] (len: 1)
cd57aad0bd45: Image
push failed
cd57aad0bd45:
Buffering to Disk
Please login prior to
push:
Username:
Error response from
daemon: no successful auth challenge for https://docker-registry.com/v2/ -
errors: [basic auth attempt to https://docker-registry.com/v2/realm "registry.localhost" failed with status: 401 Unauthorized]
#登陆后,再试
$docker login https://docker-registry.com
Username: docker
Password:
Email:
WARNING: login
credentials saved in /root/.docker/config.json
Login Succeeded
#可以push 镜像到registry
$ docker push
docker-registry.com/registry:2
The push refers to a
repository [docker-registry.com/registry] (len: 1)
cd57aad0bd45: Image
already exists
b3c39a7768ea: Image
successfully pushed
4725a48b84d4: Image
successfully pushed
7b4078296418: Image
successfully pushed
7bd663e30ad0: Image
successfully pushed
28864e830e4d: Image
successfully pushed
7bd2d56d8449: Image
successfully pushed
af88597ec24b: Image
successfully pushed
b2ae0a712b39: Image
successfully pushed
02e5bca4149b: Image
successfully pushed
895b070402bd: Image
successfully pushed
Digest:
sha256:92835b3e54c05b90e416a309d37ca02669eb5e78e14a0f5ccf44b90d4c21ed4c
搜索镜像