CentOS 7搭建Docker私人倉庫

來源:互聯網
上載者:User

標籤:docker registry

學習Docker的過程中Docker的私人倉庫一直沒能成功,就是因為CentOS 6.x和CentOS 7預設引入了支援https認證,每次在push和pull的時候都會報錯,今天是周末,利用一天的時間反覆測試和網上案列的整合,總算是成功了,也藉此機會對學習Docker的朋友有所協助。

個人的愚見:博友在練習的時候建議用CentOS 7.x系統,不建議用CentOS 6.x系統


一、準備

地址規劃:

Docker私人倉庫地址:192.168.0.109Docker用戶端地址:192.168.0.110

1、啟用網卡

# vim /etc/sysconfig/network-scripts/ifcfg-eno16777728修改此行ONBOOT=yes# /etc/init.d/network restart

2、關閉本地防火牆並設定開機不自啟動

# systemctl stop firewalld.service# systemctl disable firewalld.service

3、關閉本地selinux防火牆

# vi /etc/sysconfig/selinux SELINUX=disabled# setenforce 0

4、安裝ifconfig工具

# yum install net-tools

二、安裝

1、安裝docker

# yum install docker# yum upgrade device-mapper-libs# service docker start# chkconfig docker on

2、本地私人倉庫registry

[[email protected] ~]# docker pull registryTrying to pull repository docker.io/registry ...24dd746e9b9f: Download complete 706766fe1019: Download complete a62a42e77c9c: Download complete 2c014f14d3d9: Download complete b7cf8f0d9e82: Download complete d0b170ebeeab: Download complete 171efc310edf: Download complete 522ed614b07a: Download complete 605ed9113b86: Download complete 22b93b23ebb9: Download complete 2ac557a88fda: Download complete 1f3b4c532640: Download complete 27ebaac643a7: Download complete ce630195cb45: Download complete Status: Downloaded newer image for docker.io/registry:latest[[email protected] ~]# docker imagesREPOSITORY           TAG                 IMAGE ID            CREATED             VIRTUAL SIZEdocker.io/registry   latest              24dd746e9b9f        3 days ago          413.8 MB

3、基於私人倉庫鏡像運行容器

[[email protected] ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry docker.io/registrybb2c0d442df94e281479332c2608ef144f378e71743c5410e36b80c465771a95[[email protected] ~]# docker ps -aCONTAINER ID        IMAGE                       COMMAND             CREATED             STATUS              PORTS                    NAMESbb2c0d442df9        docker.io/registry:latest   "docker-registry"   10 seconds ago      Up 7 seconds        0.0.0.0:5000->5000/tcp   serene_hopper

4、訪問私人倉庫

[[email protected] ~]# curl 127.0.0.1:5000/v1/search{"num_results": 0, "query": "", "results": []}//私人倉庫為空白,沒有提交新鏡像到倉庫中

5、從Docker Hub上下載一個ssh鏡像

[[email protected] ~]# docker search -s 10 sshNAME                              DESCRIPTION   STARS     OFFICIAL   AUTOMATEDdocker.io: docker.io/fedora/ssh                 18                   [OK][[email protected] ~]# docker pull fedora/sshTrying to pull repository docker.io/fedora/ssh ...2aeb2b6d9705: Download complete 511136ea3c5a: Download complete 00a0c78eeb6d: Download complete 834629358fe2: Download complete 571e8a51403c: Download complete 87d5d42e693c: Download complete 92b5ef05fe68: Download complete 92d3910dc33c: Download complete cf2e9fa11368: Download complete Status: Downloaded newer image for docker.io/fedora/ssh:latest[[email protected] ~]# docker imagesREPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZEdocker.io/registry     latest              24dd746e9b9f        3 days ago          413.8 MBdocker.io/fedora/ssh   latest              2aeb2b6d9705        9 days ago          254.4 MB

6、建立鏡像連結或為基礎鏡像打個標籤

[[email protected] ~]# docker tag docker.io/fedora/ssh 127.0.0.1:5000/ssh[[email protected] ~]# docker imagesREPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZEdocker.io/registry     latest              24dd746e9b9f        3 days ago          413.8 MBdocker.io/fedora/ssh   latest              2aeb2b6d9705        9 days ago          254.4 MB127.0.0.1:5000/ssh     latest              2aeb2b6d9705        9 days ago          254.4 MB

7、修改Docker設定檔制定私人倉庫url

[[email protected] ~]# vim /etc/sysconfig/docker修改此行OPTIONS=‘--selinux-enabled --insecure-registry 192.168.0.109:5000‘[[email protected] ~]# service docker restartRedirecting to /bin/systemctl restart  docker.service

8、提交鏡像到本地私人倉庫中

[[email protected] ~]# docker push 127.0.0.1:5000/sshThe push refers to a repository [127.0.0.1:5000/ssh] (len: 1)Sending image listPushing repository 127.0.0.1:5000/ssh (1 tags)511136ea3c5a: Image successfully pushed 00a0c78eeb6d: Image successfully pushed 834629358fe2: Image successfully pushed 571e8a51403c: Image successfully pushed 87d5d42e693c: Image successfully pushed 92b5ef05fe68: Image successfully pushed 92d3910dc33c: Image successfully pushed cf2e9fa11368: Image successfully pushed 2aeb2b6d9705: Image successfully pushed Pushing tag for rev [2aeb2b6d9705] on {http://127.0.0.1:5000/v1/repositories/ssh/tags/latest}

9、查看私人倉庫是否存在對應的鏡像

[[email protected] ~]# curl 127.0.0.1:5000/v1/search{"num_results": 1, "query": "", "results": [{"description": "", "name": "library/ssh"}]}

10、查看鏡像的儲存目錄和檔案

[[email protected] ~]# tree /opt/data/registry/repositories//opt/data/registry/repositories/└── library    └── ssh        ├── _index_images        ├── json        ├── tag_latest        └── taglatest_json2 directories, 4 files

三、從私人倉庫中下載已有的鏡像

1、登陸另外一台Docker用戶端

[[email protected] ~]# ssh [email protected]The authenticity of host ‘192.168.0.110 (192.168.0.110)‘ can‘t be established.ECDSA key fingerprint is 5b:81:4b:66:d6:dd:48:16:9f:85:58:72:21:bd:ba:39.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added ‘192.168.0.110‘ (ECDSA) to the list of known hosts.[email protected]‘s password: Last login: Sun Apr 26 14:39:51 2015 from 192.168.0.103

2、修改Docker設定檔

[[email protected] ~]# vim /etc/sysconfig/docker修改此行OPTIONS=‘--selinux-enabled --insecure-registry 192.168.0.109:5000‘//添加私人倉庫地址[[email protected] ~]# service docker restartRedirecting to /bin/systemctl restart  docker.service

3、從私人倉庫中下載已有的鏡像

[[email protected] ~]# docker pull 192.168.0.109:5000/sshTrying to pull repository 192.168.0.109:5000/ssh ...2aeb2b6d9705: Download complete 511136ea3c5a: Download complete 00a0c78eeb6d: Download complete 834629358fe2: Download complete 571e8a51403c: Download complete 87d5d42e693c: Download complete 92b5ef05fe68: Download complete 92d3910dc33c: Download complete cf2e9fa11368: Download complete Status: Downloaded newer image for 192.168.0.109:5000/ssh:latest[[email protected] ~]# docker imagesREPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE192.168.0.109:5000/ssh   latest              2aeb2b6d9705        9 days ago          254.4 MB

四、瀏覽器訪問倉庫

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6B/FB/wKioL1U8yD2CICJXAACRXA3Ij1w707.jpg" title="1.png" alt="wKioL1U8yD2CICJXAACRXA3Ij1w707.jpg" />

本文出自 “鄭彥生” 部落格,請務必保留此出處http://467754239.blog.51cto.com/4878013/1638770

CentOS 7搭建Docker私人倉庫

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.