docker系列-搭建本地私有仓库-registry容器的各种坑
admin
2023-04-02 20:02:19
0

总结的坑:
a.关注daemon.json的书写格式。一句话可以错好几个点。
b.tag要清楚的表示registry服务器的信息,才能push上传成功。不是可有可无的信息。
c.tag中有版本号要清楚的写上。系统自动补全的是用latest。

####################################################################

搭建过程:
前提:通过docker pull registry下载了registry

1.新建的/etc/docker/daemon.json
[root@master docker]# cat daemon.json
{
"insecure-registries": ["172.17.0.1:5000"]
}
下面这种报错,是因为新建的/etc/docker/daemon.json文件还没有成功。
[root@master ~]# docker push 172.17.0.1:5000/hello-world
The push refers to repository [172.17.0.1:5000/hello-world]
Get https://172.17.0.1:5000/v2/: http: server gave HTTP response to HTTPS client

容易出错的4个地方:
a.错误的写成 insecure-registry.
b.错误的写成 http://172.17.0.1:5000
c.错误的用了容器的IP 172.17.0.2
d.忘记重启docker服务
#########################################################################

2.本地是否建立成功registry,可以通过docker info 查看
[root@master docker]# docker info | grep -i -A 3 regis
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
172.17.0.1:5000
127.0.0.0/8
Live Restore Enabled: false
##########################################################################

3. 启动本地registry容器,push上传image到本地registry容器
mkdir -p /data/registry
##host上创建目录volume给容器做存储
docker run -d -p 5000:5000 -v /data/registry:/var/lib/registry --name local_registry registry
##启动容器,对外用5000端口,第一个5000是host的端口,第二个5000是容器端口
[root@master docker]# docker ps | grep -i local_registry
b4c6b769aabc registry "/entrypoint.sh /etc…" About an hour ago Up 30 minutes 0.0.0.0:5000->5000/tcp local_registry
##检查registry容器是否启动

[root@master ~]# docker tag hello-world 172.17.0.1:5000/hello-world:v1
[root@master ~]# docker push 172.17.0.1:5000/hello-world:v1
The push refers to repository [172.17.0.1:5000/hello-world]
af0b15c8625b: Pushed
v1: digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a size: 524
[root@master ~]#

##注意:docker tag hello-world 172.17.0.1:5000/hello-world:v1 一定要打上正确的tag,也就是tag一定要清楚表示清楚是哪个registry。
不然,docker不知道是要将image上传到哪个registry服务器。也就是说tag包含了registry服务器的信息,不是一个可有可无的东西。

##########################################################################

4.删除host上有的images。测试从容器pull下来image。
注意:删除或者上传是如果有版本号不是latest,需要附加上。系统默认是自动补充latest,这样执行命令后反馈找不到

[root@master docker]# docker rmi 172.17.0.1:5000/hello-world
Error: No such image: 172.17.0.1:5000/hello-world
[root@master docker]# docker rmi 172.17.0.1:5000/hello-world:v1
Untagged: 172.17.0.1:5000/hello-world:v1
Untagged: 172.17.0.1:5000/hello-world@sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a
[root@master docker]#

[root@master docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mariadb latest 3a2ef06682ac 9 hours ago 356MB
wordpress latest a541a1a59631 2 days ago 447MB
busybox latest e4db68de4ff2 2 weeks ago 1.22MB
registry.aliyuncs.com/google_containers/kube-proxy v1.14.0 5cd54e388aba 3 months ago 82.1MB
registry.cn-beijing.aliyuncs.com/imcto/flannel v0.11.0-amd64 03ad33ab3dd7 3 months ago 52.6MB
registry latest f32a97de94e1 3 months ago 25.8MB
[root@master docker]#

[root@master docker]# docker pull 172.17.0.1:5000/hello-world
Using default tag: latest
Error response from daemon: manifest for 172.17.0.1:5000/hello-world:latest not found

[root@master docker]# docker pull 172.17.0.1:5000/hello-world:v1
v1: Pulling from hello-world
1b930d010525: Pull complete
Digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a
Status: Downloaded newer image for 172.17.0.1:5000/hello-world:v1
[root@master docker]#
[root@master docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mariadb latest 3a2ef06682ac 9 hours ago 356MB
wordpress latest a541a1a59631 2 days ago 447MB
busybox latest e4db68de4ff2 2 weeks ago 1.22MB
registry.cn-beijing.aliyuncs.com/imcto/flannel v0.11.0-amd64 03ad33ab3dd7 3 months ago 52.6MB
registry latest f32a97de94e1 3 months ago 25.8MB
172.17.0.1:5000/hello-world v1 fce289e99eb9 6 months ago 1.84kB
[root@master docker]#

相关内容

热门资讯

特朗普下令不打了,美国的“余粮... 可以说戛然而止,快得让很多人都无法适应。前两周,每一天美国都要打击伊朗一通。就在7月24日白宫会议前...
穆杰塔巴最新表态:支持黎真主党 △伊朗最高领袖穆杰塔巴·哈梅内伊(资料图)当地时间7月26日晚,伊朗最高领袖穆杰塔巴·哈梅内伊对黎巴...
美军瘫痪一艘驶向伊朗的油轮,特... 美国总统特朗普虽下令暂停打击伊朗,但美军仍在执行对霍尔木兹海峡的封锁任务。针对美军瘫痪一艘驶向伊朗油...
“小牌大耍”的底气到底是哪里来... 澎湃首席评论员 李平这两天,“艺人李权哲乘高铁占座事件”在网上引发热议,该艺人参加的活动主办方曾发布...
越南籍船舶南海遇险沉没,中方已... 据凤凰卫视报道,一艘越南船舶7月24日夜间在越南庆和以东220海里附近遇险沉没,船上共62名越南籍人...
李权哲占座、蒙面、装死:娱乐圈... 你买了一张高铁一等座的票,找到自己的位置,18A。有人坐着。你拿出手机看了眼购票记录——没错,18A...
杭州景区咖啡店闯入1条幼蛇,仅... 夏天气温高、湿度大,蛇类活动进入高峰期,千万别被“小蛇无害”的刻板印象骗了!有些幼蛇看着迷你可爱,实...
AI开源公开信签署企业增至50... IT之家 7 月 26 日消息,英伟达、微软、IBM、Meta 等 25 家美国科技企业本周(7 月...
南阳快手短视频代运营企业的服务... 在短视频平台快速发展的背景下,企业通过快手等渠道进行内容运营已成为常见的市场动作。对于希望借助短视频...
普通人该如何跟上科技发展的步伐 这个被称作科技的词汇, 听起来既有宏大之感, 又颇为遥远, 好似仅仅归属于在实验室里专心致志钻研的科...