3-docker 私有仓库

本文详细介绍如何搭建私有的Docker仓库,包括下载registry镜像、配置本地存储路径、解决推送镜像过程中出现的问题,以及如何查询和管理私有仓库中的镜像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装docker 参见以前文章
私有仓库的搭建

1:下载registry镜像
docker pull registry

2:通过该镜像启动容器
docker run -d -p 5000:5000 registry
默认情况下,会将仓库存放于容器内的/tmp/registry目录下,这样如果容器被删除,则存放于容器中的镜像也会丢失,所以我们一般情况下会指定本地一个目录挂载到容器内的/tmp/registry下,如下:
docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry

3:测试push到该仓库
下载nginx镜像
docker pull nginx
修改tag
doker tag nginx 10.1.4.54:5000/nginx
上传到仓库
doker push 10.1.4.54:5000/nginx
但是遇到了错误
[root@10-1-4-88 ~]# docker push 10.1.4.54:5000/nginx
The push refers to a repository [10.1.4.54:5000/nginx]
Get https://10.1.4.54:5000/v2/: http: server gave HTTP response to HTTPS client
解决办法:
[root@10-1-4-88 ~]# vi /etc/docker/daemon.json
{ "insecure-registries":["10.1.4.54:5000"] }
重起服务
[root@10-1-4-88 ~]# systemctl restart docker

在次提交
[root@10-1-4-88 ~]# docker push 10.1.4.54:5000/nginx
The push refers to a repository [10.1.4.54:5000/nginx]
54b25ecf81f0: Pushed
110566462efa: Pushed
305e2b6ef454: Pushed
24e065a5f328: Pushed
latest: digest: sha256:8f0365ebf863a78c72154bdc6af687c5c78221cf9b15ee6a0cab9a935405b38f size: 1155

4:查询私有仓库镜像
docker search 10.1.4.54:5000/
遇到错误
[root@10-1-4-88 ~]# docker search 10.1.4.54:5000/
Error response from daemon: Unexpected status code 404
查看下来不能使用docker search
解决办法:
但是通过v2 的api 可以实现相同的目的
[root@10-1-4-88 ~]# curl http://10.1.4.54:5000/v2/_catalog
{"repositories":["nginx"]}
[root@10-1-4-88 ~]# curl http://10.1.4.54:5000/v2/nginx/tags/list
{"name":"nginx","tags":["latest"]}

5:删除本地镜像在从私有仓库下载 pull
查询本地images
[root@10-1-4-88 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
10.1.4.54:5000/nginx latest 1628545933ab About an hour ago 108MB
nginx latest 1628545933ab About an hour ago 108MB
<none> <none> 1717b3a9873b About an hour ago 108MB
nginx <none> da5939581ac8 3 weeks ago 108MB
删除10.1.4.54:5000/nginx
[root@10-1-4-88 ~]# docker rmi 10.1.4.54:5000/nginx
Untagged: 10.1.4.54:5000/nginx:latest
Untagged: 10.1.4.54:5000/nginx@sha256:8f0365ebf863a78c72154bdc6af687c5c78221cf9b15ee6a0cab9a935405b38f
再次查询本地images
[root@10-1-4-88 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 1628545933ab About an hour ago 108MB
<none> <none> 1717b3a9873b About an hour ago 108MB
nginx <none> da5939581ac8 3 weeks ago 108MB
从私有仓库下载镜像10.1.4.54:5000
[root@10-1-4-88 ~]# docker pull 10.1.4.54:5000/nginx
Using default tag: latest
latest: Pulling from nginx
Digest: sha256:8f0365ebf863a78c72154bdc6af687c5c78221cf9b15ee6a0cab9a935405b38f
Status: Downloaded newer image for 10.1.4.54:5000/nginx:latest
再次查看镜像
[root@10-1-4-88 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
10.1.4.54:5000/nginx latest 1628545933ab About an hour ago 108MB
nginx latest 1628545933ab About an hour ago 108MB
<none> <none> 1717b3a9873b About an hour ago 108MB
nginx <none> da5939581ac8 3 weeks ago 108MB
[root@10-1-4-88 ~]#



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值