docker私有库搭建过程(Registry)

    xiaoxiao2023-09-11  156

    Registry实验环境:CentOS7Docker

    1、安装并运行registry安装:[root@docker01 ~]# docker pull registryUsing default tag: latestTrying to pull repository docker.io/library/registry ... latest: Pulling from docker.io/library/registry79650cf9cc01: Pull complete 70ce42745103: Pull complete 77edd1a7fa4d: Pull complete 432773976ace: Pull complete 3234a47fe5a9: Pull complete Digest: sha256:a3551c422521617e86927c3ff57e05edf086f1648f4d8524633216ca363d06c2[root@docker01 ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/busybox latest c30178c5239f 6 days ago 1.106 MBdocker.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 registry75841a99e1fc882617bc37d088a8c80abae225cfe2842110f2049600df560a47[root@docker01 ~]# -d后台运行-p指定端口-v把registry的镜像路径/var/lib/registry映射到本机的/mnt/date/registry

    检查5000端口netstat -an | grep 5000[root@docker01 ~]# netstat -an | grep 5000tcp6 0 0 :::5000 :::* LISTEN [root@docker01 ~]#

    telnet 127.0.0.1 5000成功。[root@docker01 ~]# telnet 127.0.0.1 5000Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is '^]'.qHTTP/1.1 400 Bad RequestContent-Type: text/plainConnection: 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 imagesREPOSITORY TAG IMAGE ID CREATED SIZE10.100.50.122:5000/busybox latest c30178c5239f 6 days ago 1.106 MBdocker.io/busybox latest c30178c5239f 6 days ago 1.106 MBdocker.io/registry latest 9d0c4eabab4d 6 weeks ago 33.17 MB[root@registry ~]#

    3、上传镜像报错[root@registry xinetd.d]# docker push 10.100.50.120:5000/busyboxThe 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/busyboxThe 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 registryWARNING: 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 registryabbec57e5dca734689cfd953f27564156ec24e32ae6e532043309f0332653650[root@registry mnt]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESabbec57e5dca 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/search404 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

    相关资源:Docker 搭建私有仓库(registry、harbor)
    最新回复(0)