/* 从官网下载的镜像,因为官网是在国外,所以要下载使用的话,不方便 所以就要建立一个本地的docker仓库 容器中的网络和宿主机的网络是不相关的。 但是如果从外面去访问容器是无法访问的,所以要利用-p来对端口映射 --5000:5000 左边是宿主机的端口,右边是容器的端口 */ [root@localhost ~]# docker pull registry //registry为docker官方的一个镜像,用它来创建本地的docker私有仓库 latest: Pulling from registry 9b7301678506: Pull complete d912f6ed534e: Pull complete 664daba008e5: Pull complete 33e9a84661e7: Pull complete 5366f93a80af: Pull complete 8d1f9ff6843f: Pull complete 79a50c6b6f41: Pull complete 94c689ffd50b: Pull complete ad8da6d14f6d: Pull complete Digest: sha256:ebe6779a71971307f9577a2f172c2f24cf8b37bb7e22a076f47a9df4dcdcc625 Status: Downloaded newer image for registry:latest //以registry镜像启动容器,监听5000端口 [root@localhost ~]# docker run -d -p 5000:5000 registry 6ce6bc5b805600d86057cc45de27d5cedc1fdc2224def5115ed376c5fb464a99 [root@localhost ~]# curl 127.0.0.1:5000 //访问 //把镜像上传到私有仓库 [root@localhost ~]# docker tag frankie_test 192.168.216.129:5000/centos /* 对tag进行标记 并带着私有仓库的 ip:port */
此处出现错误如下:
解决方法:
[root@localhost ~]# docker push 192.168.216.129:5000/centos //报错类似如下 Error response from daemon: invalid registry endpoint https://192.168.216.129:5000/v0/:unable to ping registry endpoint https://192.168.216.129:5000/v0/v2 ping attempt failed with error: Get https://192.168.216.129:5000/v2/: EOF v1 ping attempt failed with error: Get https://192.168.216.129:5000/v1/_ping: EOF, If this private registry supports only HTTP or HTTPS with an unknown CA certificate,please add `--insecure-registry 192.168.216.129:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/192.168.216.129:5000/ca.crt --> 这是因为Docker从1.3.X之后,与docker registry交互默认使用的时https,然后此处搭建的私有仓库只提供http服务,所以当与私有仓库交互时就会报上面的错误。为了解决这个问题需要在启动docker server时增加启动参数为默认使用http访问。 [root@localhost ~]# vi /etc/init.d/docker //change $exec -d $other_args --> change to -->$exec -d --insecure-registry 192.168.216.129:5000 $other_args [root@localhost ~]# /etc/init.d/docker restart [root@localhost ~]# docker start registry_container_id //查看私有仓库里的所有镜像 [root@localhost ~]# curl http://192.168.216.129:5000/v1/search