Registry
实验环境:
CentOS7
Docker
1、安装并运行registry
安装:
[root@docker01 ~]# docker pull registry
Using default tag: latest
Trying to pull repository docker.io/library/registry ...
latest: Pulling from docker.io/library/registry
79650cf9cc01: Pull complete
70ce42745103: Pull complete
77edd1a7fa4d: Pull complete
432773976ace: Pull complete
3234a47fe5a9: Pull complete
Digest: sha256:a3551c422521617e86927c3ff57e05edf086f1648f4d8524633216ca363d06c2
[root@docker01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/busybox latest c30178c5239f 6 days ago 1.106 MB
docker.io/registry latest 9d0c4eabab4d 6 weeks ago 33.17 MB
[root@docker01 ~]#
运行:
[root@docker01 ~]# docker run -d -p 5000:5000 -v /mnt/date/registry:/var/lib/registry registry
75841a99e1fc882617bc37d088a8c80abae225cfe2842110f2049600df560a47
[root@docker01 ~]#
-d后台运行
-p指定端口
-v把registry的镜像路径/var/lib/registry映射到本机的/mnt/date/registry
检查5000端口
netstat -an | grep 5000
[root@docker01 ~]# netstat -an | grep 5000
tcp6 0 0 :::5000 :::* LISTEN
[root@docker01 ~]#
telnet 127.0.0.1 5000成功。
[root@docker01 ~]# telnet 127.0.0.1 5000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
q
HTTP/1.1 400 Bad Request
Content-Type: text/plain
Connection: close
400 Bad RequestConnection closed by foreign host.
[root@docker01 ~]#
2、添加tag标记
[root@registry ~]# docker tag busybox 10.100.50.120:5000/busybox
[root@registry ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
10.100.50.122:5000/busybox latest c30178c5239f 6 days ago 1.106 MB
docker.io/busybox latest c30178c5239f 6 days ago 1.106 MB
docker.io/registry latest 9d0c4eabab4d 6 weeks ago 33.17 MB
[root@registry ~]#
3、上传镜像报错
[root@registry xinetd.d]# docker push 10.100.50.120:5000/busybox
The push refers to a repository [10.100.50.122:5000/busybox]
Get https://10.100.50.120:5000/v1/_ping: http: server gave HTTP response to HTTPS client
[root@registry xinetd.d]#
解决方案:
修改/etc/sysconfig/docker文件,并重新启动docker服务。
ADD_REGISTRY='--add-registry 10.100.50.120:5000'
INSECURE_REGISTRY='--insecure-registry 10.100.50.120:5000'
4、上传镜像
[root@registry ~]# docker push 10.100.50.120:5000/busybox
The push refers to a repository [10.100.50.120:5000/busybox]
3a1dff9afffd: Pushed
latest: digest: sha256:be3c11fdba7cfe299214e46edc642e09514dbb9bbefcd0d3836c05a1e0cd0642 size: 527
[root@registry ~]#
其他坑:
坑1:
IPV4 forwording报错,但是容器运行正常。
[root@registry mnt]# docker run -d -p 5000:5000 -v /mnt/date/registry registry
WARNING: IPv4 forwarding is disabled. Networking will not work.
970e18480c47661fd2cffab9f7e0410989e62ed9d229333cb32e5727a2e88b3b
[root@registry mnt]#
解决方案:
在/etc/sysctl.conf文件中加入net.ipv4.ip_forward=1并重启网络服务。
修改后正常:
[root@registry mnt]# docker run -d -p 5000:5000 -v /mnt/date/registry registry
abbec57e5dca734689cfd953f27564156ec24e32ae6e532043309f0332653650
[root@registry mnt]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abbec57e5dca registry "/entrypoint.sh /etc/" 31 seconds ago Up 30 seconds 0.0.0.0:5000->5000/tcp compassionate_mclean
[root@registry mnt]#
坑2:
查看镜像存放位置显示404 page not found网上很多教程都是下面这个命令
[root@docker01 ~]# curl http://10.100.50.122:5000/v2/search
404 page not found
通过docker search registry发现安装的是2.0版本。
V2的命令格式如下:
[root@docker01 ~]# curl -X GET http://10.100.50.122:5000/v2/_catalog
{"repositories":["busybox","centos"]}
[root@docker01 ~]#
文档:http://www.jianshu.com/p/fc36368b5c44