Registry的文档还是相对详尽的。在文档中,我们找到了 Insecure Registry ,即接收plain http访问的Registry的配置和使用方法,虽然这不是官方推荐的。
实际上对于我们内部网络而言,Insecure Registry基本能满足需求,部署过程也避免了secure registry的那些繁琐步骤,比如制作和部署证书等。
为了搭建一个Insecure Registry,我们需要先清理一下上面已经启动的Registry容器。
$ docker stop registry
registry
$ docker rm registry
registry
修改Registry server上的Docker daemon的配置,为DOCKER_OPTS增加–insecure-registry:
DOCKER_OPTS="--insecure-registry 10.10.105.71:5000 ....
重启Docker Daemon,启动Registry容器:
$ sudo service docker restart
docker stop/waiting
docker start/running, process 6712
$ sudo docker run -d -p 5000:5000 -v `pwd`/data:/var/lib/registry --restart=always --name registry registry:2
5966e92fce9c34705050e19368d19574e021a272ede1575385ef35ecf5cea019
尝试再次Push image:
$ docker push 10.10.105.71:5000/tonybai/busybox
The push refers to a repository [10.10.105.71:5000/tonybai/busybox] (len: 1)
65e4158d9625: Pushed
5506dda26018: Pushed
latest: digest: sha256:800f2d4558acd67f52262fbe170c9fc2e67efaa6f230a74b41b555e6fcca2892 size: 2739
这回push ok!
我们将本地的tag做untag处理,再从Registry pull相关image:
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2 c457c689c328 9 days ago 165.7 MB
10.10.105.71:5000/tonybai/busybox latest 65e4158d9625 9 days ago 1.114 MB
busybox latest 65e4158d9625 9 days ago 1.114 MB
ubuntu 14.04 6cc0fc2a5ee3 5 weeks ago 187.9 MB
$ docker rmi 10.10.105.71:5000/tonybai/busybox
Untagged: 10.10.105.71:5000/tonybai/busybox:latest
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2 c457c689c328 9 days ago 165.7 MB
busybox latest 65e4158d9625 9 days ago 1.114 MB
ubuntu 14.04 6cc0fc2a5ee3 5 weeks ago 187.9 MB
$ docker pull 10.10.105.71:5000/tonybai/busybox
Using default tag: latest
latest: Pulling from tonybai/busybox
Digest: sha256:800f2d4558acd67f52262fbe170c9fc2e67efaa6f230a74b41b555e6fcca2892
Status: Downloaded newer image for 10.10.105.71:5000/tonybai/busybox:latest
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry 2 c457c689c328 9 days ago 165.7 MB
10.10.105.71:5000/tonybai/busybox latest 65e4158d9625 9 days ago 1.114 MB
busybox latest 65e4158d9625 9 days ago 1.114 MB
ubuntu 14.04 6cc0fc2a5ee3 5 weeks ago 187.9 MB
可以看到:Pull过程也很顺利。
在Private Registry2中查看或检索Repository或images, 将不能用docker search :
$ docker search 10.10.105.71:5000/tonybai/busybox/
Error response from daemon: Unexpected status code 404
但通过v2版本的API,我们可以实现相同目的:
$curl http://10.10.105.71:5000/v2/_catalog
{"repositories":["tonybai/busybox"]}
$ curl http://10.10.105.71:5000/v2/tonybai/busybox/tags/list
{"name":"tonybai/busybox","tags":["latest"]}
在其他主机上,我们尝试pull busybox:
10.10.105.72:
$docker pull 10.10.105.71:5000/tonybai/busybox
Using default tag: latest
Error response from daemon: unable to ping registry endpoint https://10.10.105.71:5000/v0/
v2 ping attempt failed with error: Get https://10.10.105.71:5000/v2/: tls: oversized record received with length 20527
v1 ping attempt failed with error: Get https://10.10.105.71:5000/v1/_ping: tls: oversized record received with length 20527
我们发现依旧不能pull和push!在Registry手册中讲到,如果采用insecure registry的模式,那么所有与Registry交互的主机上的Docker Daemon都要配置:–insecure-registry选项。
我们按照上面的配置方法,修改105.72上的/etc/default/docker,重启Docker daemon,再执行pull/push就会得到正确的结果:
$ sudo vi /etc/default/docker
$ sudo service docker restart
docker stop/waiting
docker start/running, process 10614
$ docker pull 10.10.105.71:5000/tonybai/busybox
Using default tag: latest
latest: Pulling from tonybai/busybox
5506dda26018: Pull complete
65e4158d9625: Pull complete
Digest: sha256:800f2d4558acd67f52262fbe170c9fc2e67efaa6f230a74b41b555e6fcca2892
Status: Downloaded newer image for 10.10.105.71:5000/tonybai/busybox:latest
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 36248ae4a9ac 8 days ago 187.9 MB
10.10.105.71:5000/tonybai/ubuntu 14.04 36248ae4a9ac 8 days ago 187.9 MB
10.10.105.71:5000/tonybai/busybox latest 65e4158d9625 9 days ago 1.114 MB
$ docker push 10.10.105.71:5000/tonybai/ubuntu
The push refers to a repository [10.10.105.71:5000/tonybai/ubuntu] (len: 1)
36248ae4a9ac: Pushed
8ea5373bf5a6: Pushed
2e0188208e83: Pushed
e3c70beaa378: Pushed
14.04: digest: sha256:72e56686cb9fb38438f0fd68fecf02ef592ce2ef7069bbf97802d959d568c5cc size: 6781