本文主要是介绍docker简单私有仓库的搭建,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
示例: 【搭建简单的Registry仓库】
1. 下载 Registry 镜像
[root@docker ~]# docker pull registry
#可以查看开放的端口,需要把端口暴露出来
[root@docker ~]# docker history registry:latest
[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
## 推上去的数据在哪?
[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
真机中位于:
# 最终数据位于容器的:
# 进去真机中的路径下看看,有 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
[root@docker ~]# curl 172.25.254.5:5000/v2/_catalog
{"repositories":["nginx.v3"]}
{"repositories":["nginx.v3"]}
# 再推一个试试:
[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
这篇关于docker简单私有仓库的搭建的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!