13.docker私服registry搭建

容器注册

Docker Hub是最大、使用最广泛的docker容器注册托管中心。

  • registry用于保存docker镜像,包括镜像的层次结构和元数据。
  • 启动容器时,docker daemon会试图从本地获取相关的镜像;本地镜像不存在时,其将从registry中下载该镜像并保存到本地;
  • 拉取镜像时,如果不知道registry仓库地址,默认从Docker Hub搜索拉取镜像

我们可以利用docker自己搭建私有registry。一般私有registry不像docker hub功能齐全,而是只提供了基础功能,比较适合小团队。

启动私有docker registry

启动docker registry

bash 复制代码
docker container run -d -p 5000:5000 --name registry registry

docker container ls
# CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS                  PORTS                    NAMES
# d88855125dd4   registry      "/entrypoint.sh /etc..."   1 second ago     Up Less than a second   0.0.0.0:5000->5000/tcp   registry

重新给镜像打标签,并且推送到私有registry

bash 复制代码
docker pull hello-world

docker run --name hello hello-world 

docker tag hello-world 127.0.0.1:5000/hello-world

docker image ls

docker push 127.0.0.1:5000/hello-world

docker container rm hello

docker image remove hello-world

docker image remove 127.0.0.1:5000/hello-world

docker image ls

从本地删除对应镜像缓存

从私有registry尝试拉取镜像

bash 复制代码
docker pull 127.0.0.1:5000/hello-world

docker image ls

将私有registry的数据持久化到宿主机

bash 复制代码
docker container kill registry

docker container rm registry

docker container run -d -p 5000:5000 --name registry -v $(pwd)/registry-date:/var/lib/registry registry

ls -al

docker push 127.0.0.1:5000/hello-world

ls -al

tree registry-date

使用Swarm将registry部署到线上

使用swarm部署registry服务,利用routing mesh特性

我们先部署5个manager节点,

bash 复制代码
docker node ls

docker service create --name registry --publish 5000:5000 registry

docker service ps registry
# ID             NAME         IMAGE             NODE       DESIRED STATE   CURRENT STATE            ERROR     PORTS
# jfwgt7gmwu62   registry.1   registry:latest   manager1   Running         Running 13 seconds ago  

利用routing mesh特性,我们可以在任意节点上从私有registry拉取镜像

bash 复制代码
curl localhost:5000/v2/_catalog
# {"repositories":[]}

docker pull hello-world

docker tag hello-world 127.0.0.1:5000/hello-world

docker push 127.0.0.1:5000/hello-world

curl localhost:5000/v2/_catalog
# {"repositories":["hello-world"]}


docker pull nginx

docker tag nginx 127.0.0.1:5000/nginx

docker push 127.0.0.1:5000/nginx

curl localhost:5000/v2/_catalog

docker service create --name nginx -p 80:80 --replicas 5 --detach=false 127.0.0.1:5000/nginx

docker service ps nginx

可以看到5个节点都成功拉取到了私服的镜像

相关推荐
闻哥12 小时前
从 AJAX 到浏览器渲染:前端底层原理与性能指标全解析
java·前端·spring boot·ajax·okhttp·面试
「QT(C++)开发工程师」13 小时前
C++ 多种单例模式
java·c++·单例模式
何以不说话13 小时前
记录一下学习日常⑩(docker)
linux·运维·docker·容器
短剑重铸之日13 小时前
《SpringCloud实用版》统一认证授权:Spring Authorization Server + OAuth2 + JWT 生产级方案
java·后端·spring·jwt·oauth2
哲-哲13 小时前
WVP+ZLM搭建碰到问题
java
编程彩机13 小时前
互联网大厂Java面试:从Spring Cloud到分布式事务的技术场景解析
java·spring cloud·微服务·消息队列·分布式事务
黎雁·泠崖13 小时前
Java内部类与匿名内部类:定义+类型+实战应用
java·开发语言
青槿吖13 小时前
第二篇:JDBC进阶骚操作:防注入、事务回滚、连接池优化,一篇封神
java·开发语言·jvm·算法·自动化
青&棠13 小时前
JDK 多版本管理工具 jvms
java
FITA阿泽要努力13 小时前
Agent Engineer-Day 1 初始智能体与大语言模型基础
java·前端·javascript