Docker--------registry私人倉庫搭建 [ Http ]

來源:互聯網
上載者:User

標籤:registry   docker   docker hub   

1. 背景

    docker中要使用鏡像,一般會從本地、docker Hup公用倉庫和其它第三方公用倉庫中下載鏡像,一般出於安全和外網(牆)資源下載速率的原因考慮企業級上不會輕易使用。那麼有沒有一種辦法可以儲存自己的鏡像的倉庫呢? ----> 企業級環境中搭建自己的私人倉庫。


2. 私人倉庫有優勢:

    一、節省網路頻寬,針對於每個鏡像不用每個人都去中央倉庫上面去下載,只需要從私人倉庫中下載即可;

    二、提供鏡像資源利用,針對於公司內部使用的鏡像,推送到本地的私人倉庫中,以供公司內部相關人員使用。


3. 環境:

[[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [[email protected] ~]# uname -r3.10.0-327.36.3.el7.x86_64


4. 伺服器Ip地址

    192.168.60.150


5. 安裝:

 * 安裝docker

[[email protected] ~]# yum install docker


 * 啟動docker服務

[[email protected] ~]# systemctl start docker


 * 設定docker服務開機啟動

[[email protected] ~]# systemctl enable docker


 * 拉取 registry鏡像,例如在daocloud.io/registry這個私人鏡像倉庫

[[email protected] ~]# docker pull daocloud.io/registry


 * 建立本地鏡像儲存目錄

[[email protected] ~]# mkdir /data/local_docker_registry -p


 * 運行容器,設定容器名稱為local_docker_registry, 掛在鏡像內docker鏡像倉庫/var/lib/registry 至本地/data/local_docker_registry目錄,並曝光5000連接埠, --restart=always讓其跟隨docker啟動時啟動

[[email protected] ~]# docker run --name local_docker_registry --restart=always -d -v /data/local_docker_registry:/var/lib/registry -p 5000:5000 daocloud.io/registry


 * 測試 [ 有返回就表示成功 ]

[[email protected] ~]# curl 192.168.60.150:5000/v2<a href="/v2/">Moved Permanently</a>.


6. 上傳鏡像至私人倉庫測試

 * 編寫dockerfile檔案

# Nginx # Version 1.0.1# Author lisea# Url https://lisea.cn# Base imgaeFROM centos# MaintainerMAINTAINER lisea [email protected]# CommandsRUN rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpmRUN yum install nginx -yRUN echo "daemon off;" >> /etc/nginx/nginx.confRUN echo "this is test nginx image" > /usr/share/nginx/html/index.htmlEXPOSE 80CMD ["nginx"]


 * 通過Dockerfile構建一個新鏡像, 直接指明registry和標籤

[[email protected] nginx]# docker build -t 192.168.60.150:5000/nginx:1.0.1 .


 * push 上傳鏡像到私人倉庫

[[email protected] nginx]# docker push 192.168.60.150:5000/nginx:1.0.1


 * 查看鏡像是否上傳成功

[[email protected] nginx]# curl 192.168.60.150:5000/v2/_catalog{"repositories":["nginx"]}

 

 * 其它伺服器使用此鏡像

[[email protected] nginx]# docker pull 192.168.60.150:5000/nginx:1.0.1


7. 相關問題

  * 可能會出現無法push鏡像到私人倉庫的問題。這是因為我們啟動的registry服務不是安全可信賴的。     解決:

   1. 需要修改docker的設定檔 /etc/sysconfig/docker-network,在添加下面的內容,

    DOCKER_NETWORK_OPTIONS="--insecure-registry 192.168.60.150:5000"

      2. 重啟docker

[[email protected] nginx]# systemctl restart docker



8. 總結



以需求驅動技術,技術本身沒有優略之分,只有業務之分。


本文出自 “sea” 部落格,請務必保留此出處http://lisea.blog.51cto.com/5491873/1934617

Docker--------registry私人倉庫搭建 [ Http ]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.