docker registry实践

首先得从hub上获取官方的镜像

docker pull registry

官方示例:

$ docker run -d -p 5000:5000 --restart always --name registry registry:2

$ docker pull ubuntu

$ docker tag ubuntu localhost:5000/ubuntu

$ docker push localhost:5000/ubuntu

我的实践:
我有俩台机器,分别是
192.168.227.133 (各种作的机器)
192.168.227.134 (准备作为一个服务器)

在192.168.227.134上建立仓库,并运行

$ docker pull registry
$ docker run -d -p 5000:5000 --restart always --name registry registry:2

添加信赖

访问 http://192.168.227.134:5000/v2/ 不通或者在其他机器上远程push时报错,比如" dial tcp 192.168.227.134:5000: i/o timeout"等,有可能是因为我们启动的registry服务不是安全可信赖的。我们需要修改docker的配置文件/etc/default/docker,添加下面的内容 DOCKER_OPTS="--insecure-registry xxx.xxx.xxx.xxx:5000"
切换到root用户

vim /etc/default/docker

添加如下:

DOCKER_OPTS="--insecure-registry 192.168.227.134:5000"

重启docker服务:

service docker restart

在客户机上测试一下。首先打个tag,然后push。

kring@userver:~$ docker images
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
sath89/oracle-12c                  latest              3e5a125f224e        3 days ago          5.69 GB
isuper/java-oracle                 latest              4bbd500474b6        7 days ago          311 MB
tomcat                             latest              4452dae04daa        2 weeks ago         355 MB
mysql                              latest              22be5748ecbe        2 weeks ago         406 MB
ubuntu                             latest              0ef2e08ed3fa        2 weeks ago         130 MB
wnameless/oracle-xe-11g            latest              51fad6f11394        5 weeks ago         2.24 GB
192.168.227.134:5000/hello-world   test                48b5124b2768        2 months ago        1.84 kB
192.168.227.134:5000/hello-world   test1               48b5124b2768        2 months ago        1.84 kB
hello-world                        latest              48b5124b2768        2 months ago        1.84 kB
centos                             latest              67591570dd29        3 months ago        192 MB


kring@userver:~$ docker tag sath89/oracle-12c:latest 192.168.227.134:5000/sath89/oracle-12c

kring@userver:~$ docker push 192.168.227.134:5000/sath89/oracle-12c
The push refers to a repository [192.168.227.134:5000/sath89/oracle-12c]
82c8c528e609: Pushed
e276bf45da60: Pushed
032e683277c4: Pushed
105daf83e29c: Pushed
0488c9e2de86: Pushed
5f70bf18a086: Pushed
1f253a0703ec: Pushed
80ec921b230b: Pushed
227021bc9aa6: Pushed
latest: digest: sha256:d6ebb5f95352169731c5f8b3fa71e2b60f693c40f18e7f03cdeacafc363d904d size: 3022

push有可能会遇到 “server gave HTTP response to HTTPS client”,这个问题可能是由于客户端采用https,docker registry未采用https服务所致。
解决方案:
在”/etc/docker/“目录下,创建”daemon.json“文件。在文件中写入:

{ "insecure-registries":["192.168.1.100:5000"] }

保存退出后,重启docker。

查看镜像列表

curl http://192.168.227.134:5000/v2/_catalog
添加新评论