Docker入门与应用系列(六)Docker私有与公共镜像仓库


1.搭建私有镜像仓库

Docker Hub作为Docker默认官方公共镜像;
如果想搭建自己的私有镜像仓库,官方提供registry镜像,使搭建私有仓库非常简单

1.1下载registry镜像并启动

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

1.2 测试,查看镜像仓库中所有的镜像

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

1.3 配置私有仓库可信任

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

1.4 打标签

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.5 上传镜像

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.6 下载镜像

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.7 列出仓库镜像标签

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 don't 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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM