1. 实验环境
两台docker主机:
docker主机:192.168.183.189
镜像仓库:192.168.183.188
2. 仓库搭建
docker主机ip:192.168.183.188
2.1 拉取registry镜像
[root@localhost ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
0a6724ff3fcd: Pull complete
d550a247d74f: Pull complete
1a938458ca36: Pull complete
acd758c36fc9: Pull complete
9af6d68b484a: Pull complete
Digest: sha256:d5459fcb27aecc752520df4b492b08358a1912fcdfa454f7d2101d4b09991daa
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@localhost ~]#
2.2 基于registry镜像运行registry容器
[root@localhost ~]# docker run --name registry -d -p 5000:5000 --restart always registry
5a5bd6f0b415c53d0668dff2013dbc4ab347f7ae06c92e5d2f0a3e1805cc6e43
2.3 查看运行的registry容器
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5a5bd6f0b415 registry "/entrypoint.sh /etc…" 33 seconds ago Up 33 seconds 0.0.0.0:5000->5000/tcp registry
[root@localhost ~]#
3. 配置docker主机:192.168.183.189
3.1 修改docker的配置文件
配置私库地址insecure-registries和端口号
[root@localhost ~]# vim /etc/docker/daemon.json
[root@localhost ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://q3u0qv3z.mirror.aliyuncs.com"],
"insecure-registries":["192.168.153.188:5000"]
}
[root@localhost ~]#
3.2 重启docker
[root@localhost ~]# systemctl restart docker
3.3 给本地镜像打标签成标准格式
[root@localhost ~]# docker tag mysql:5.7 192.168.153.188:5000/mysql:5.7
3.4 推送本地镜像到registry仓库中
推送成功
[root@localhost ~]# docker push 192.168.153.188:5000/mysql:5.7
The push refers to repository [192.168.153.188:5000/mysql]
6c316520569e: Pushed
f6bef35c0067: Pushed
a6ea401b7864: Pushed
94bd7d7999de: Pushed
8df989cb6670: Pushed
f358b00d8ce7: Pushed
ae39983d39c4: Pushed
b55e8d7c5659: Pushed
e8fd11b2289c: Pushed
e9affce9cbe8: Pushed
316393412e04: Pushed
d0f104dc0a1f: Pushed
5.7: digest: sha256:b9c1994c82f94c13370b0d79efa703616a538bf55fcb7e0923892d5a5e753514 size: 2829
[root@localhost ~]#
3.5 删除本地mysql镜像
[root@localhost ~]# docker rmi mysql:5.7
Untagged: mysql:5.7
[root@localhost ~]# docker rmi -f 192.168.153.188:5000/mysql:5.7
Untagged: 192.168.153.188:5000/mysql:5.7
Untagged: 192.168.153.188:5000/mysql@sha256:b9c1994c82f94c13370b0d79efa703616a538bf55fcb7e0923892d5a5e753514
Deleted: sha256:a4cc8ac4386762cd0e8e3d9c7ca4ba6e84898aff2995762baaf47aef8cbaf063
[root@localhost ~]#
3.6 从registry中拉取镜像测试
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@localhost ~]# docker pull 192.168.153.188:5000/mysql:5.7
5.7: Pulling from mysql
bf5952930446: Already exists
8254623a9871: Already exists
938e3e06dac4: Already exists
ea28ebf28884: Already exists
f3cef38785c2: Already exists
894f9792565a: Already exists
1d8a57523420: Already exists
5f09bf1d31c1: Already exists
1b6ff254abe7: Already exists
74310a0bf42d: Already exists
d398726627fd: Already exists
784aa83a1bf2: Already exists
Digest: sha256:b9c1994c82f94c13370b0d79efa703616a538bf55fcb7e0923892d5a5e753514
Status: Downloaded newer image for 192.168.153.188:5000/mysql:5.7
192.168.153.188:5000/mysql:5.7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.153.188:5000/mysql 5.7 a4cc8ac43867 3 months ago 448MB
[root@localhost ~]#