1. Docker Registry
網上有很多的Registry服務器都支持第三方用戶注冊,而后基于用戶名去做自己的倉庫,但是使用互聯網上的Registry有一個缺陷,那就是我們去推送和下載鏡像時都不會很快,而在生產環境中很可能并行啟動的容器將達到幾十、上百個,而且很有可能每個服務器本地是沒有鏡像的,此時如果通過互聯網去下載鏡像會有很多問題,比如下載速度會很慢、帶寬會用很多等等,如果帶寬不夠的話,下載至啟動這個過程可能要持續個幾十分鐘,這已然違背了使用容器會更加輕量、快速的初衷和目的。因此,很多時候我們很有可能需要去做自己的私有Registry。
Docker Registry分類:
Sponsor Registry:第三方的Registry,供客戶和Docker社區使用
Mirror Registry:第三方的Registry,只讓客戶使用
Vendor Registry:由發布docker鏡像的供應商提供的registry
Private Registry:通過設有防火墻和額外的安全層的私有實體提供的registry
事實上,如果運維的系統環境托管在云計算服務上,比如阿里云,那么用阿里云的Registry則是最好的選擇。很多時候我們的生產環境不會在本地,而是托管在數據中心機房里,如果我們在數據中心機房里的某臺主機上部署Registry,因為都在同一機房,所以屬于同一局域網,此時數據傳輸走內網,效率會極大的提升。
所有的Registry默認情況下都是基于https工作的,這是Docker的基本要求,而我自建Registry時很可能是基于http工作的,但是Docker默認是拒絕使用http提供Registry服務的,除非明確的告訴它,我們就是要用http協議的Registry。
2. Docker私有Registry
為了幫助我們快速創建私有Registry,Docker專門提供了一個名為docker-distribution的軟件包,我們可以通過安裝這個軟件包快速構建私有倉庫。
當然,官方也提供了Registry的鏡像,我們可以直接將其pull到本地并啟動為容器即可快速實現私有Registry。
在node01上使用自建的Registry去上傳鏡像
//使用insecure-registries參數添加http支持
[root@node01 ~]# vim /etc/docker/daemon.json
{
? ? "registry-mirrors": ["https://registry.docker-cn.com"],
? ? "insecure-registries": ["172.16.78.128:5000"]
}
[root@node01 ~]# systemctl restart docker
//將本地鏡像傳到自建的registry中
[root@node01 ~]# docker images ? ? ? ? ? ?
REPOSITORY ? ? ? ? ?TAG ? ? ? ? ? ? ? ? IMAGE ID ? ? ? ? ? ?CREATED ? ? ? ? ? ? SIZE
docker.io/httpd ? ? latest ? ? ? ? ? ? ?a6ea92c35c43 ? ? ? ?3 weeks ago ? ? ? ? 166 MB
[root@node01 ~]# docker tag httpd:latest node02:5000/httpd:latest
[root@node01 ~]# docker images
REPOSITORY ? ? ? ? ?TAG ? ? ? ? ? ? ? ? IMAGE ID ? ? ? ? ? ?CREATED ? ? ? ? ? ? SIZE
172.16.78.128:5000/httpd ? latest ? ? ? ? ? ? ?a6ea92c35c43 ? ? ? ?3 weeks ago ? ? ? ? 166 MB
docker.io/httpd ? ? latest ? ? ? ? ? ? ?a6ea92c35c43 ? ? ? ?3 weeks ago ? ? ? ? 166 MB
[root@node01 ~]# docker push 172.16.78.128:5000/httpd
The push refers to a repository [172.16.78.128:5000/httpd]
88b680b1fdfc: Pushed?
843c3701e622: Pushed?
3ba8a4f66ba2: Pushed?
c865989f86f7: Pushed?
d0f104dc0a1f: Pushed?
latest: digest: sha256:fc717ed0d0b55ada05af1c1a95a2d4ee1153a5858fd65b654644a1a5add0c28b size: 1367
在node01上使用自建的Registry去上傳鏡像
//使用insecure-registries參數添加http支持
[root@node01 ~]# vim /etc/docker/daemon.json
{
? ? "registry-mirrors": ["https://registry.docker-cn.com"],
? ? "insecure-registries": ["172.16.78.128:5000"]
}
[root@node01 ~]# systemctl restart docker
//將本地鏡像傳到自建的registry中
[root@node01 ~]# docker images ? ? ? ? ? ?
REPOSITORY ? ? ? ? ?TAG ? ? ? ? ? ? ? ? IMAGE ID ? ? ? ? ? ?CREATED ? ? ? ? ? ? SIZE
docker.io/httpd ? ? latest ? ? ? ? ? ? ?a6ea92c35c43 ? ? ? ?3 weeks ago ? ? ? ? 166 MB
[root@node01 ~]# docker tag httpd:latest node02:5000/httpd:latest
[root@node01 ~]# docker images
REPOSITORY ? ? ? ? ?TAG ? ? ? ? ? ? ? ? IMAGE ID ? ? ? ? ? ?CREATED ? ? ? ? ? ? SIZE
172.16.78.128:5000/httpd ? latest ? ? ? ? ? ? ?a6ea92c35c43 ? ? ? ?3 weeks ago ? ? ? ? 166 MB
docker.io/httpd ? ? latest ? ? ? ? ? ? ?a6ea92c35c43 ? ? ? ?3 weeks ago ? ? ? ? 166 MB
[root@node01 ~]# docker push 172.16.78.128:5000/httpd
The push refers to a repository [172.16.78.128:5000/httpd]
88b680b1fdfc: Pushed?
843c3701e622: Pushed?
3ba8a4f66ba2: Pushed?
c865989f86f7: Pushed?
d0f104dc0a1f: Pushed?
latest: digest: sha256:fc717ed0d0b55ada05af1c1a95a2d4ee1153a5858fd65b654644a1a5add0c28b size: 1367
?
?