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 测试,查看镜像仓库中所有的镜像
[email protected]:~# curl http://192.168.1.82:5000/v2/_catalog {"repositories":[]}
1.2 私有仓库管理
1.2.1 配置私有仓库可信任
[email protected]:~# cat /etc/docker/daemon.json #需要创建此文件 { "insecure-registries":["192.168.1.82:5000"] } [email protected]-node3:~# systemctl restart docker
1.2.2 打标签
[email protected]:~# docker tag centos:6 192.168.1.82:5000/centos:6 [email protected]-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 上传镜像
[email protected]:~# 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 [email protected]-node3:~# curl http://192.168.1.82:5000/v2/_catalog {"repositories":["centos"]}
1.2.4 下载镜像
[email protected]:~# 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 列出仓库镜像标签
[email protected]:~# 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
[[email protected] ~]# 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 上传
[email protected]:~# 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