测试
接下来我们就要操作把一个本地镜像push到私有仓库中。首先在119机器下pull一个比较小的镜像来测试(此处使用的是busybox)。
$ sudo docker pull busybox
C:\Users\Administrator\AppData\Local\YNote\data\qq41E380972A3128D92AECC7E981CEFD76\1a5ef83b528c47639784db78ca92f082\05142818687.jpeg
接下来修改一下该镜像的tag。
$ sudo docker tag busybox 192.168.99.109:5000/busybox
C:\Users\Administrator\AppData\Local\YNote\data\qq41E380972A3128D92AECC7E981CEFD76\4b52ce62c9f543dab69a16826e951d99\05142942508.jpeg
接下来把打了tag的镜像上传到私有仓库。
$ sudo docker push 192.168.99.109:5000/busybox
C:\Users\Administrator\AppData\Local\YNote\data\qq41E380972A3128D92AECC7E981CEFD76\d80ea396048c4704b2f9d19112aeb7a9\05143057014.jpeg
可以看到push失败,具体错误如下:
[iyunv@docker ~]# docker push 192.168.99.109:5000/busybox
The push refers to a repository [192.168.99.109:5000/busybox]
unable to ping registry endpoint https://192.168.99.109:5000/v0/
v2 ping attempt failed with error: Get https://192.168.99.109:5000/v2/: http: server gave HTTP response to HTTPS client
v1 ping attempt failed with error: Get https://192.168.99.109:5000/v1/_ping: http: server gave HTTP response to HTTPS client
因为Docker从1.3.X之后,与docker registry交互默认使用的是https,然而此处搭建的私有仓库只提供http服务,所以当与私有仓库交互时就会报上面的错误。为了解决这个问题需要在启动docker server时增加启动参数为默认使用http访问。修改docker启动配置文件(此处是修改132机器的配置)Ubuntu下配置文件地址为:/etc/systemconfig/docker,在其中增加–insecure-registry 192.168.99.109:5000如下所示:
[iyunv@docker ~]# cat /etc/sysconfig/docker
# /etc/sysconfig/docker
# Modify these options if you want to change the way the docker daemon runs
#OPTIONS='--selinux-enabled --log-driver=journald'
OPTIONS='--selinux-enabled=false --insecure-registry gcr.io' OPTIONS='--selinux-enabled --insecure-registry 192.168.99.109:5000'
DOCKER_CERT_PATH=/etc/docker
..........
docker pull 192.168.112.136:5000/busybox
[iyunv@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.99.109:5000/busybox latest e02e811dd08f 10 weeks ago 1.093 MB