示例: 【搭建简单的Registry仓库】
1.
下载
Registry
镜像
[root@docker ~]# docker pull registry
![](https://i-blog.csdnimg.cn/direct/194209001f33416096793cf2df1ea099.png)
#可以查看开放的端口,需要把端口暴露出来
[root@docker ~]# docker history registry:latest
![](https://i-blog.csdnimg.cn/direct/07c5d3cdd00b44a7a68b9dbbf9dc9a2f.png)
[root@docker ~]# docker run -d -p 5000:5000 --restart=always registry
9f389c98fbd2163fb6487a5bfd2358751eb4ecb07eb47f463ae76f12b117361c
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f389c98fbd2 registry "/entrypoint.sh /etc…" 14 seconds ago Up 12 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp hardcore_saha
9f389c98fbd2163fb6487a5bfd2358751eb4ecb07eb47f463ae76f12b117361c
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f389c98fbd2 registry "/entrypoint.sh /etc…" 14 seconds ago Up 12 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp hardcore_saha
#推送push #把当前镜像 nginx:v2 推送到 5000 端口
[root@docker ~]# docker tag nginx:v2 172.25.254.5:5000/nginx.v3
[root@docker ~]# docker push 172.25.254.5:5000/nginx.v3
Using default tag: latest
The push refers to repository [172.25.254.5:5000/nginx.v3]
Get "https://172.25.254.5:5000/v2/": http: server gave HTTP response to HTTPS client
Using default tag: latest
The push refers to repository [172.25.254.5:5000/nginx.v3]
Get "https://172.25.254.5:5000/v2/": http: server gave HTTP response to HTTPS client
## 默认用 https 的方式:得做认证
[root@docker ~]#
[root@docker ~]#
#也可以不用https,而用http的方式,必须得配置非加密端口信息。/etc/docker/daemon.json
[root@docker ~]# vim /etc/docker/daemon.json
[root@docker ~]# cat /etc/docker/daemon.json
{
"insecure-registries" : ["http://172.25.254.5:5000"]
}
[root@docker ~]# cat /etc/docker/daemon.json
{
"insecure-registries" : ["http://172.25.254.5:5000"]
}
[root@docker ~]# systemctl restart docker
[root@docker ~]# docker push 172.25.254.5:5000/nginx.v3
Using default tag: latest
The push refers to repository [172.25.254.5:5000/nginx.v3]
54a2c5fcea1c: Pushed
a8df99e45168: Pushed
174f56854903: Pushed
latest: digest: sha256:2d45824da0f28c4087c7a2c009cc4dba14efc637fdd8bef91fd49a1dcbda8b8c size: 947
[root@docker ~]# docker push 172.25.254.5:5000/nginx.v3
Using default tag: latest
The push refers to repository [172.25.254.5:5000/nginx.v3]
54a2c5fcea1c: Pushed
a8df99e45168: Pushed
174f56854903: Pushed
latest: digest: sha256:2d45824da0f28c4087c7a2c009cc4dba14efc637fdd8bef91fd49a1dcbda8b8c size: 947
![](https://i-blog.csdnimg.cn/direct/02b6884a500f4354a1b320ef784e4a4c.png)
## 推上去的数据在哪?
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f389c98fbd2 registry "/entrypoint.sh /etc…" 13 minutes ago Up 4 minutes 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp hardcore_saha
[root@docker ~]# docker inspect hardcore_saha
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f389c98fbd2 registry "/entrypoint.sh /etc…" 13 minutes ago Up 4 minutes 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp hardcore_saha
[root@docker ~]# docker inspect hardcore_saha
真机中位于:
![](https://i-blog.csdnimg.cn/direct/10aceca56cd64cee936c187e42e5d9b4.png)
# 最终数据位于容器的:
![](https://i-blog.csdnimg.cn/direct/b97038fa1e704eb1a2102dfe4976169b.png)
# 进去真机中的路径下看看,有 nginx:v3
[root@docker ~]# cd /var/lib/docker/volumes/fbc4139d10af9999ee19f7856fb7b5d187337af25eb9c927ef0e99eff304f0f0/_data
[root@docker _data]# ls
docker
[root@docker _data]# cd docker/
[root@docker docker]# cd registry/
[root@docker registry]# ls
v2
[root@docker registry]# cd v2/
[root@docker v2]# ls
blobs repositories
[root@docker v2]# cd repositories/
[root@docker repositories]# l
bash: l: command not found...
[root@docker repositories]# ls
nginx.v3
[root@docker _data]# ls
docker
[root@docker _data]# cd docker/
[root@docker docker]# cd registry/
[root@docker registry]# ls
v2
[root@docker registry]# cd v2/
[root@docker v2]# ls
blobs repositories
[root@docker v2]# cd repositories/
[root@docker repositories]# l
bash: l: command not found...
[root@docker repositories]# ls
nginx.v3
![](https://i-blog.csdnimg.cn/direct/f6d46761c2df41ee872cd74b0818b0ab.png)
[root@docker ~]# curl 172.25.254.5:5000/v2/_catalog
{"repositories":["nginx.v3"]}
{"repositories":["nginx.v3"]}
![](https://i-blog.csdnimg.cn/direct/5730a5d46a3840a2870b68bfc15de4d5.png)
# 再推一个试试:
[root@docker ~]# docker tag busybox:latest 172.25.254.5:5000/busybox:xixi
[root@docker ~]# docker push 172.25.254.5:5000/busybox:xixi
The push refers to repository [172.25.254.5:5000/busybox]
d51af96cf93e: Pushed
xixi: digest: sha256:28e01ab32c9dbcbaae96cf0d5b472f22e231d9e603811857b295e61197e40a9b size: 527
[root@docker ~]# docker push 172.25.254.5:5000/busybox:xixi
The push refers to repository [172.25.254.5:5000/busybox]
d51af96cf93e: Pushed
xixi: digest: sha256:28e01ab32c9dbcbaae96cf0d5b472f22e231d9e603811857b295e61197e40a9b size: 527
![](https://i-blog.csdnimg.cn/direct/6622b99b91de40948cae1d1ef3a44ffb.png)