centos7上搭建docker私有仓库

来源:互联网 发布:release 变量被优化 编辑:程序博客网 时间:2024/06/06 00:58

私有仓库主机(centos7):10.60.34.46
客户机(centos7):client

私有仓库主机上:

  1. 下载registry镜像

    docker pull registry
  2. 运行registry容器,为了在容器关闭时不删除仓库目录,需要把仓库目录挂载到宿主机目录

    docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry

客户机上:

  1. 获取一个小的镜像busybox用于测试

    docker pull busybox
  2. 修改busybox的标签,用于上传到私有仓库

    docker tag busybox 10.60.34.46:5000/busybox
  3. 上传

    docker push 10.60.34.46:5000/busybox

    这里会出现错误:

    Error response from daemon: unable to ping registry endpoint https://10.60.34.46:5000/v0/v2 ping attempt failed with error: Get https://10.60.34.46:5000/v2/: EOF v1 ping attempt failed with error: Get https://10.60.34.46:5000/v1/_ping: EOF

    原因是与私有仓库的默认交互方式是https,而私有仓库主机只提供http服务。可以在客户端docker的启动配置文件中加入参数:-–insecure-registry=10.60.34.46:5000来规避这个问题。

    vi /usr/lib/systemd/system/docker.service
    [Service]Type=notifyExecStart=/usr/bin/docker daemon -H fd:// --insecure-registry=10.60.34.46:5000

    重启docker:

    systemctl daemon-reloadservice docker restart

    再次上传:

    [root@bogon ~]# docker push 10.60.34.46:5000/busyboxThe push refers to a repository [10.60.34.46:5000/busybox] (len: 1)Sending image listPushing repository 10.60.34.46:5000/busybox (1 tags)Image cfa753dfea5e already pushed, skippingImage d7057cb02084 already pushed, skippingPushing tag for rev [d7057cb02084] on {http://10.60.34.46:5000/v1/repositories/busybox/tags/latest}

    查看私有仓库:

    [root@bogon ~]# curl http://10.60.34.46:5000/v1/search{"num_results": 2, "query": "", "results": [{"description": "", "name": "library/centos"}, {"description": "", "name": "library/busybox"}]}

    查询镜像:

    [root@bogon ~]# curl http://10.60.34.46:5000/v1/search?q=busybox{"num_results": 1, "query": "busybox", "results": [{"description": "", "name": "library/busybox"}]}

    获取镜像:

    docker pull 10.60.34.46:5000/busybox
0 0
原创粉丝点击