介紹:
Registry用於保存docker鏡像,包括鏡像的層次結構和元數據
用戶可自建Registry,也可使用官方的Docker Hub
分類:
- Sponsor Registry: 第三方的registry,供客戶和Docker社區使用
- Mirror Registry: 第三方的registry,只讓客戶使用
- Vendor Registry: 由發布Docker鏡像的供應商提供的registry
- Private Registry: 通過設有防火牆和額外的安全層的私有實體提供的
安裝docker-resitry:
~]# yum -y install docker-registry
查看docker-registry安裝后各目錄:
~]# rpm -ql docker-registry /etc/docker-distribution/registry/config.yml // registry的配置文件 /usr/bin/registry // registry命令程序所在目錄 /usr/lib/systemd/system/docker-distribution.service /usr/share/doc/docker-distribution-2.6.2 /usr/share/doc/docker-distribution-2.6.2/AUTHORS /usr/share/doc/docker-distribution-2.6.2/CONTRIBUTING.md /usr/share/doc/docker-distribution-2.6.2/LICENSE /usr/share/doc/docker-distribution-2.6.2/MAINTAINERS /usr/share/doc/docker-distribution-2.6.2/README.md /var/lib/registry // 鏡像所存位置
查看docker-registry的配置文件:
~]# cat /etc/docker-distribution/registy/config.yml version: 0.1 log: fields: service: registry storage: cache: layerinfo: inmemory // 緩存在內存中 filesystem: rootdirectory: /var/lib/registry // 數據存儲路徑 http: addr: :5000 // 監聽端口
啟動服務:
~]# systemctl start docker-distribution ~]# ss -nlt | grep 5000
LISTEN 0 128 :::5000 :::*
推送鏡像到registry:
~]# docker images ..... myweb v0.3-9 7d72ff5e7b03 2 hours ago 16MB
.....
~]# docker tag myweb:v0.3-9 hadoop2:5000/myweb:v0.3-9 // 要將tag改為registry服務器的hostname:port/tag
~]# docker push hadoop2:5000/myweb:v0.3-9 // 推送鏡像到resistry,第一次會報錯,因為客戶端默認使用https協議
Get https://hadoop2:5000/v2/: http: server gave HTTP response to HTTPS client
~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://l10nt4hq.mirror.aliyuncs.com"], // 鏡像下載加速
"bip": "10.0.0.1/16", // docker橋的地址,新建容器時會依次分配地址
"hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"], // 允許對外監聽
"insecure-registries": ["hadoop2:5000"] // 添加此行
}
~]# systemctl restart docker // 重啟服務生效
~]# docker push hadoop2:5000/myweb:v0.3-9 // 再次推送,成功
~]# ll /var/lib/registry // 會生成一個docker目錄,數據都在docker目錄下
docker