詳解Docker私有倉庫最簡便的搭建方法
Doker 在業(yè)界的應(yīng)用越來越廣泛,怎么用戶管理好自己的鏡像、容器等就是一個迫在眉睫的任務(wù)。
由于業(yè)務(wù)需要,我們需要在搭建一套自己的 Docker 私有鏡像倉庫,網(wǎng)上找了很多,都是說要 pull 一個 regisitry 鏡像,然后通過這個鏡像啟動一個容器來運(yùn)行倉庫應(yīng)用,我按照官網(wǎng)的說明 pull 了一個 registry ,但是啟動的時候有報錯,具體是什么就不細(xì)說了,反正是有錯,于是開始研究別的方法,別說還真找到了一個,而且是我發(fā)現(xiàn)的最簡便的辦法,我不知道我是不是國內(nèi)第一個發(fā)現(xiàn)的,但我應(yīng)該是第一個寫出來給大家參考的。
下面不廢話,直接說方法:
- 首先,你的系統(tǒng)要是 CentOS 7.0 以上,因?yàn)閮?nèi)核的要求,以及各種相關(guān)的庫和軟件的需要,以及 epel 的需要。
- 直接安裝 docker-registry 這個包。
- 稍微修改一下配置,讓你的私有倉庫支持 http,因?yàn)閺?docker1.3.2 開始,docker registry 默認(rèn)都是使用 https 協(xié)議而不使用 http,甭管你從 docker hub 上找你需要的鏡像,還是你自己打出來的 private registry。
- 重啟相關(guān)的 docker 服務(wù)。
- 測試及使用。
下面就詳細(xì)列一下每一步的步驟:
使用 CentOS 7.X 系統(tǒng),添加 epel 源,并更新系統(tǒng)到最新版本,重啟讓新的內(nèi)核生效。
#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo #yum clean all #yum makecache #yum update -y #reboot
安裝 docker 相關(guān)的服務(wù),其中 docker-registry 這個最重要,因?yàn)檫@就是私有倉庫的服務(wù),有了這個服務(wù)就不需要像網(wǎng)上一樣去 pull 鏡像,然后再起一個容器。
#yum install docker docker-registry -y
如果不需要開發(fā)相關(guān)的接口調(diào)用程序,這兩個就夠了,如果需要開發(fā)就直接安裝所有的 docker 包,一共也沒幾個。但是最好把 docker-latest 和 docker-latest-logrotate 兩個包卸載掉,因?yàn)檫@倆是 docker 客戶端,版本是 1.12 跟 server 的版本 1.10 不是太匹配。
#yum install docker* -y #yum remove docker-latest* -y
把 docker 的兩個服務(wù)設(shè)置為自動啟動,并讓其運(yùn)行。
#systemctl enable docker #systemctl start docker #systemctl enable docker-registry #systemctl start docker-registry
查看一下本機(jī)監(jiān)聽的端口,是不是有5000這個端口了?5000端口就是默認(rèn)的 docker-registry 監(jiān)聽端口,當(dāng)然,這個你可以根據(jù)自己喜歡進(jìn)行修改。
[root@01 /]# netstat -tnlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1109/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1384/master tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 20437/python tcp6 0 0 :::22 :::* LISTEN 1109/sshd tcp6 0 0 ::1:25 :::* LISTEN 1384/master
測試一下是不是能通過網(wǎng)絡(luò)進(jìn)行訪問了?
[root@01 /]# curl "http://192.168.1.107:5000" "\\"docker-registry server\\""[root@01 /]# [root@01 /]#
既然可以訪問了,那就往這上面 push 一個鏡像來測試一下吧。這個需要你首先 tag 一個鏡像,然后才能 push 上去。以我目前的已經(jīng)有的鏡像為例。
[root@01 /]# docker tag cfba59e097ba 192.168.1.107:5000/test1 [root@01 /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.1.107:5000/test1 latest ac0b483c17fa 3 days ago 634.6 MB docker.io/redmine latest cfba59e097ba 3 days ago 634.6 MB docker.io/registry latest c9bd19d022f6 2 weeks ago 33.27 MB [root@01 /]#
現(xiàn)在 push 的話有報錯,如下。
[root@01 /]# docker pull 192.168.1.107:5000/test1 Using default tag: latest Trying to pull repository 192.168.1.107:5000/test1 ... unable to ping registry endpoint https://192.168.1.107:5000/v0/ v2 ping attempt failed with error: Get https://192.168.1.107:5000/v2/: EOF v1 ping attempt failed with error: Get https://192.168.1.107:5000/v1/_ping: EOF [root@01 /]#
但是基本上一眼就能看出來,地址里都是 https,而我現(xiàn)在能訪問的只是 http,所以,就需要解決啟用 http 的問題,因?yàn)槲业男枨笫窃趦?nèi)網(wǎng)里搭建,外網(wǎng)無法訪問,何必要加密,只會拖慢速度。接下來就是修改對應(yīng)的配置文件,啟用 http ,這個配置文件也是有說這個有說那個的,下面的才是正確的配置文件,親測有效,如下。
[root@01 /]# vim /etc/sysconfig/docker
把下面這一行添加進(jìn)去。
OPTIONS='--insecure-registry 192.168.1.107:5000'
重啟 docker 服務(wù)。
[root@01 /]# systemctl restart docker docker-registry
再次 push,成功完成。
[root@01 system]# docker push 192.168.1.107:5000/test1 The push refers to a repository [192.168.1.107:5000/test1] 07c28c5d0371: Image successfully pushed 6365a80ad26a: Image successfully pushed c5e7c0f1d017: Image successfully pushed b45f06d28f46: Image successfully pushed 3f3c0394ba5a: Image successfully pushed ddd6e2a8209e: Image successfully pushed f306cb9361f7: Image successfully pushed 2d143a3783bc: Image successfully pushed f110684b8ae3: Image successfully pushed d7d24df90586: Image successfully pushed e26addf75a78: Image successfully pushed 82c666956815: Image successfully pushed 9a2b1c643e93: Image successfully pushed eb9546f264dc: Image successfully pushed f96222d75c55: Image successfully pushed Pushing tag for rev [cfba59e097ba] on {http://192.168.1.107:5000/v1/repositories/test1/tags/latest} [root@01 system]#
既然成功了,就往下 pull 一下試試,看看能不能讓別的機(jī)器用,結(jié)果當(dāng)然也是成功的,因?yàn)槲乙呀?jīng) pull 過了,所以顯示鏡像已經(jīng)存在,如下。
[root@01 /]# docker pull 192.168.1.107:5000/test1 Using default tag: latest Trying to pull repository 192.168.1.107:5000/test1 ... Pulling repository 192.168.1.107:5000/test1 cfba59e097ba: Already exists f96222d75c55: Already exists d17727727b61: Already exists 92db66c8ffce: Already exists 10a436a2f8fa: Already exists 8b40995a66da: Already exists a2cba87d9ea4: Already exists 5a187c7a57c4: Already exists d15f50d30606: Already exists 4366383cdf86: Already exists c7cb938f30c3: Already exists f135d604f740: Already exists 3f3d23c69aef: Already exists e6adcc9c0e4b: Already exists 53289b480679: Already exists Status: Image is up to date for 192.168.1.107:5000/test1:latest 192.168.1.107:5000/test1: this image was pulled from a legacy registry. Important: This registry version will not be supported in future versions of docker. [root@01 /]#
至此,簡單的私有倉庫已經(jīng)搭建完畢,后續(xù)如果有需求要在公網(wǎng)上提供服務(wù)的話,加 SSL 證書,加用戶名/密碼等操作按部就班地去完成就行了。IT 技術(shù)更新很快,可能之前還沒有這個服務(wù),只是最近才有,所以,選了這一行就需要一輩子不斷學(xué)習(xí)不斷進(jìn)步才能站在橋頭迎風(fēng)斬浪。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
使用docker創(chuàng)建集成服務(wù)lnmp環(huán)境
本篇文章主要介紹了使用docker創(chuàng)建集成服務(wù)lnmp環(huán)境,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-04-04解決Docker中的error during connect異常情況
這篇文章主要介紹了解決Docker中的error during connect異常情況,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11windows server 2016安裝docker的方法步驟
這篇文章主要介紹了windows server 2016安裝docker的方法步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-06-06如何使用docker+frp進(jìn)行內(nèi)網(wǎng)穿透
這篇文章主要介紹了使用docker+frp進(jìn)行內(nèi)網(wǎng)穿透,在公網(wǎng)上的ubuntu系統(tǒng)需要配置相關(guān)操作,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-04-04