歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習Linux

centos7系統下搭建docker本地鏡像倉庫

centos7系統下搭建docker本地鏡像倉庫


熱度3 評論 38 www.BkJia.Com  網友分享於:  2017-02-28 06:02:52     浏覽數3126次

centos7系統下搭建docker本地鏡像倉庫


准備工作

用到的工具, Xshell5, Xftp5,Docker.io/registry:latest鏡像, 宿主機IP:192.168.199.131

關於docker的安裝和設置加速, 請參考這篇博文centos7系統下 docker 環境搭建

設置完加速後, 執行docker pull registry命令, 下載docker.io/registry官方鏡像

啟動registry鏡像

啟動docker.io/registry容器, 如果tag是latest, 可以忽略不寫

docker run -d -p 80:5000 --restart=always --name local_registry docker.io/registry:latest

-d 後台運行 -p 端口映射, 宿主機80端口映射給容器的5000端口 –restart=always 容器意外關閉後, 自動重啟 (如果重啟docker服務, 帶這個參數的, 能自動啟動為Up狀態, 不帶這個的,不會自動啟動) –name 給容器起個名字, 可以根據這個名字去停止/啟動/刪除容器

配置端口開放

[root@localhost docker]# firewall-cmd --zone=public --add-port=80/tcp --permanentsuccess[root@localhost docker]# firewall-cmd --list-allpublic (active)  target: default  icmp-block-inversion: no  interfaces: eth0  sources:   services: dhcpv6-client ssh  ports:   protocols:   masquerade: no  forward-ports:   sourceports:   icmp-blocks:   rich rules: [root@localhost docker]# firewall-cmd --reloadsuccess[root@localhost docker]# firewall-cmd --list-allpublic (active)  target: default  icmp-block-inversion: no  interfaces: eth0  sources:   services: dhcpv6-client ssh  ports: 80/tcp  protocols:   masquerade: no  forward-ports:   sourceports:   icmp-blocks:   rich rules: 

配置端口開放之後, 需要執行firewall-cmd –reload才能生效

重命名鏡像

[root@localhost docker]# docker imagesREPOSITORY                                           TAG                 IMAGE ID            CREATED             SIZErepos_local/zookeeper                                0.0.1               bdb481b4f17a        2 days ago          541.5 MB

repos_local/zookeeper 是上篇博文介紹的使用Dockerfile文件創建的鏡像, 重命名

docker tag repos_local/zookeeper:0.0.1 192.168.199.131/repos_local/zookeeper:latest

docker tag 原鏡像名:tag 新鏡像名:tag

docker images 查看鏡像名稱是否更改正確

[root@localhost docker]# docker imagesREPOSITORY                                           TAG                 IMAGE ID            CREATED             SIZE192.168.199.131/repos_local/zookeeper                latest              bdb481b4f17a        2 days ago          541.5 MB

推送鏡像

docker push 192.168.199.131/repos_local/zookeeper:latest

如果提示以下錯誤, 說明沒有把搭建的registry加入可信任的列表裡面, 如果有https域名或者能創建.crt證書, 那麼可以忽略以下步驟

Error response from daemon: invalid registry endpoint https://192.168.199.131/v0/: unable to ping registry endpoint https://192.168.199.131/v0/v2 ping attempt failed with error: Get https://192.168.199.131/v2/: dial tcp 192.168.199.131:443: no route to host v1 ping attempt failed with error: Get https://192.168.199.131/v1/_ping: dial tcp 192.168.199.131:443: no route to host. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 192.168.199.131` 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.199.131/ca.crt

解決方法:

只針對centos7下 Docker version 1.12.5, build 047e51b/1.12.5版本有效, 其它版本沒做過測試

vi /etc/sysconfig/docker

注意–insecure-registry 192.168.199.131插入的位置

# Modify these options if you want to change the way the docker daemon runsOPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --insecure-registry 192.168.199.131'if [ -z "${DOCKER_CERT_PATH}" ]; then    DOCKER_CERT_PATH=/etc/dockerfi

重啟docker服務

systemctl restart docker.service

重新執行docker push 192.168.199.131/repos_local/zookeeper:latest , 這次應該就能成功了

查看鏡像倉庫

[root@localhost docker]# curl 192.168.199.131/v2/_catalog{"repositories":["repos_local/zookeeper"]}[root@localhost docker]# curl 192.168.199.131/v2/repos_local/zookeeper/tags/list{"name":"repos_local/zookeeper","tags":["latest"]}

至於鏡像的刪除, 目前還沒找到一個好的解決方法, 如有建議請留言

http://www.bkjia.com/Linuxjc/1196005.htmlwww.bkjia.comtrue

Copyright © Linux教程網 All Rights Reserved