docker私有仓库regidtry
下载registry和nignx
//
[root@docker ~]# docker pull registry
[root@docker ~]# docker pull nginx
docker引擎终端设置仓库地址
//
[root@localhost ~]# cd /etc/docker
[root@localhost docker]# ls
daemon.json key.json
[root@localhost docker]# vim daemon.json
{
"insecure-registries": ["192.168.142.141:5000"],
"registry-mirrors": ["https://m1aaxlq9.mirror.aliyuncs.com"]
}
[root@localhost docker]# systemctl restart docker
宿主机的 /data/registry 自动创建挂载容器中的 /tmp/registry
//
[root@localhost ~]# docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry
a663dac65316e6cc6b1b9885560492cf2fe0a5da0529bcc923f28543202b8b3e
打标签
//
[root@localhost ~]# docker tag nginx:latest 192.168.142.141:5000/nginx
上传镜像到私有仓库
//
[root@localhost ~]# docker push 192.168.142.141:5000/nginx
获取私有仓库镜像列表
//
[root@localhost ~]# curl -XGET http://192.168.142.141:5000/v2/_catalog
再上传centos:7
//
[root@localhost ~]# docker tag centos:7 192.168.142.141:5000/centos:7
[root@localhost ~]# docker push 192.168.142.141:5000/centos:7
The push refers to repository [192.168.142.141:5000/centos]
174f56854903: Pushed
7: digest: sha256:e4ca2ed0202e76be184e75fb26d14bf974193579039d5573fb2348664deef76e size: 529
[root@localhost ~]# curl -XGET http://192.168.142.141:5000/v2/_catalog
{"repositories":["centos","nginx"]}
先删除本地镜像
//
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.142.141:5000/nginx latest ad4c705f24d3 4 days ago 133MB
nginx latest ad4c705f24d3 4 days ago 133MB
registry latest b2cb11db9d3d 13 days ago 26.2MB
192.168.142.141:5000/centos 7 8652b9f0cb4c 10 months ago 204MB
centos 7 8652b9f0cb4c 10 months ago 204MB
[root@localhost ~]# docker rmi 192.168.142.141:5000/nginx
[root@localhost ~]# docker rmi 192.168.142.141:5000/centos:7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ad4c705f24d3 4 days ago 133MB
registry latest b2cb11db9d3d 13 days ago 26.2MB
centos 7 8652b9f0cb4c 10 months ago 204MB
测试能否从私有仓库下载镜像
//
[root@localhost ~]# docker pull 192.168.142.141:5000/nginx
[root@localhost ~]# docker pull 192.168.142.141:5000/centos:7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.142.141:5000/nginx latest ad4c705f24d3 4 days ago 133MB
nginx latest ad4c705f24d3 4 days ago 133MB
registry latest b2cb11db9d3d 13 days ago 26.2MB
192.168.142.141:5000/centos 7 8652b9f0cb4c 10 months ago 204MB
centos 7 8652b9f0cb4c 10 months ago 204MB