0
点赞
收藏
分享

微信扫一扫

创建自己的私有仓库

柠檬的那个酸_2333 2022-04-13 阅读 32
docker

创建自己的私有仓库

1.查看docker hub上的registry容器镜像

[root@localhost ~]# docker search centos

1649500834848.png

2.将registry镜像拉到本地

[root@localhost ~]# docker pull registry

1649500867954.png

3.启动容器

[root@localhost ~]# docker run -d -p 5000:5000 --restart=always -v registry:/var/lib/registry registry:lat                       est
0e5b5b3fbc14db3bfb9d1e9850b415d270f0d424d6d6e507fc39c658371e3c42

1649500964844.png

遇到下面这个错是因为在启动docker容器的时候或者做docker配置的时候,还对防火墙设置重新启动等配置
这样会清除docker的相关配置,导致在查询防火墙规则的时候显示不到docker的链

而docker容器的底层原理:
在启动docker的时候会自动在iptables中注册一个链,通过防火墙的链也可以找到其注册的信息,主要注册这些链,是docker中的容器为了暴露端口而使用的

具体原因是你删除了iptables中的链

  • 重启firewalld防火墙即可对其清除,firewalld是centos7以上,iptables是centos6以下都会有,而firewalld的底层是涉及在iptables上的,在启动firewalld的时候会自动删除iptables链的相关链接

那么 我们只需要将其重启docker容器即可解决该问题

systemctl restart docker

1649506503060.png

4.在防火墙里放行TCP 5000端口

[root@localhost ~]# firewall-cmd --add-port=5000/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success

1649501056112.png

5.验证

[root@localhost ~]# curl http://192.168.87.147:5000/v2/_catalog
{"repositories":[]}

1649501133867.png

6.dockers registry V2 版本客户端默认使用https协议去push镜像到仓库服务器,而现在我们的仓库 服务器只配置了支持http,所以客户端会push镜像失败

[root@localhost ~]# docker tag hello-world:latest 192.168.87.147:5000/hello-world:latest
[root@localhost ~]# docker push 192.168.87.147:5000/hello-world:latest
The push refers to repository [192.168.87.147:5000/hello-world]
Get "https://192.168.87.147:5000/v2/": http: server gave HTTP response to HTTPS client

1649501251674.png

7. 如要希望docker客户端支持http协议,需在启动docker时加入参数 --insecure-registry your_registry_ip:port

[root@localhost ~]# vim /etc/docker/daemon.json
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker.service

1649501388578.png

在编写/etc/docker/daemon.json时,不同行要用逗号隔开否则在重启docker.service会报错

1649501538754.png

8. 重新push镜像,发现成功

[root@localhost ~]# docker push 192.168.87.147:5000/hello-world:latest

镜像,发现成功**

[root@localhost ~]# docker push 192.168.87.147:5000/hello-world:latest

1649501613378.png

举报

相关推荐

0 条评论