1. 程式人生 > >Docker入門與應用系列(六)Docker私有與公共鏡像倉庫

Docker入門與應用系列(六)Docker私有與公共鏡像倉庫

nbsp one 默認 span epo refers 1.8 png list

1.搭建私有鏡像倉庫
Docker Hub作為Docker默認官方公共鏡像;
如果想搭建自己的私有鏡像倉庫,官方提供registry鏡像,使搭建私有倉庫非常簡單
1.1.1下載registry鏡像並啟動

docker pull registry
docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry

1.1.2 測試,查看鏡像倉庫中所有的鏡像

root@linux-node3:~# curl http://192.168.1.82:5000/v2/_catalog
{"
repositories":[]}

1.2 私有倉庫管理
1.2.1 配置私有倉庫可信任

root@linux-node3:~# cat /etc/docker/daemon.json #需要創建此文件
{ "insecure-registries":["192.168.1.82:5000"] }
root@linux-node3:~# systemctl restart docker

1.2.2 打標簽

root@linux-node3:~# docker tag centos:6 192.168.1.82:5000/centos:6
root@linux-node3:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 177391bcf802 
2 weeks ago 33.3MB 192.168.1.82:5000/centos 6 df3764b1d215 2 weeks ago 194MB centos 6 df3764b1d215 2 weeks ago 194MB

1.2.3 上傳鏡像

root@linux-node3:~# docker push 192.168.1.82:5000/centos:6
The push refers to a repository [192.168.1.82:5000/centos]
13d6d4fbf536: Pushed 
6: digest: sha256:82adb6d4b857ffd254af8041957df8481c84a9a1b9fdcc6efc4ba6432b1d6940 size: 529
root@linux-node3:~# curl http://192.168.1.82:5000/v2/_catalog {"repositories":["centos"]}

1.2.4 下載鏡像

root@linux-node3:~# docker pull 192.168.1.82:5000/centos:6
6: Pulling from centos
Digest: sha256:82adb6d4b857ffd254af8041957df8481c84a9a1b9fdcc6efc4ba6432b1d6940
Status: Image is up to date for 192.168.1.82:5000/centos:6

1.2.5 列出倉庫鏡像標簽

root@linux-node3:~# curl http://192.168.1.82:5000/v2/centos/tags/list
{"name":"centos","tags":["6"]}

2.公共倉庫
2.1 註冊賬號
https://hub.docker.com
2.2 登陸Docker hub

[root@localhost ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you dont have a Docker ID, head over to https://hub.docker.com to create one.
Username: syavingc
Password: 
Login Succeeded

docker login --username-syavingc --password=123456

2.3 鏡像打標簽

docker tag centos:6 syavingc/centos:6

2.4 上傳

root@linux-node3:~# docker push syavingc/centos:6
The push refers to a repository [docker.io/syavingc/centos]
6c44122e3bf1: Pushed 
bd020e07e375: Pushed 
51f0477e960f: Pushed 
cf80bccaefdb: Pushed 
f413106c0a75: Pushed 
13d6d4fbf536: Mounted from library/centos 
6: digest: sha256:e9c108ce15700392f101e950d8138d3becf534f5179f0432a7c2c56f56507e88 size: 1576

技術分享圖片

#搜索測試

dicker search syavingc

2.5 下載

docker pull syavingc/cenots:6

Docker入門與應用系列(六)Docker私有與公共鏡像倉庫