搭建Docker镜像私服
需求,原理,需要达成的效果都和Maven私服类似,没啥好说的
Docker官方的registry
这玩意还是之前开始了解Docker时用过,要了解的移步其他文章
Nexus
其实就综合评分而言,Harbor更有优势;但作为Java程序员出身,早早就使用了Nexus作为Maven私服,对这款软件有种莫名的好感,再者,就日常使用而言,Nexus作为Docker私服也是完全足够的;所以个人选择了Nexus。
至于Harbor就搭建时略有区别,针对docker的配置都是大同小异的,读者可借鉴思路。
开始
-
搭建Nexus环境
这里使用Docker-compose搭建
脚本version: "3.8" services: nexus: image: sonatype/nexus3:3.33.1 container_name: nexus_3_33_1 restart: always privileged: true ports: - '18081:8081' - '5000:5000' - '15000:15000' volumes: - 'nexus_data:/nexus-data' volumes: nexus_data: {}运行
docker-compose up -d结果

-
配置仓库
宿主仓库



代理仓库


其余默认即可;
同上再加入docker中央仓库(https://registry-1.docker.io)
仓库组
其实这几个仓库的概念和Maven私服非常相似


至此,Nexus服务端的仓库配置基本完成
- 配置客户端
打开Docker配置文件
若没有配置文件,则新建,该配置文件为Json格式vim /etc/docker/daemon.json
加入以下内容
重新服务"insecure-registries":["192.168.0.114:15000","192.168.0.114:5000"]
测试客户端[root@kapana docker-compose]# systemctl daemon-reload [root@kapana docker-compose]# systemctl restart docker.service
分别登录两个仓库[root@origin ~]# docker login 192.168.0.114:15000 Username: admin Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded[root@origin ~]# docker login 192.168.0.114:5000 Username: admin Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded - 配置免密拉取镜像
默认,Nexus要求用户必须先登录授权才能拉取镜像,但在某些场景下这是不合理的,为此需要配置部分仓库免密拉取-
创建免密拉取角色
原本想直接修改匿名角色,但是系统不让修改;直接新建一个角色

-
创建一个匿名拉取的用户
同样的,这里原本是想直接修改匿名用户,直接追加新角色的,但实验了很多次,也翻了些文档还是没解决,所以直接新建一个匿名拉取的用户,将这个用户赋予原有的匿名角色和新建的角色

-
配置匿名访问

-
测试匿名拉取
清除本地已授权信息[root@origin ~]# docker logout 192.168.0.114:5000 Removing login credentials for 192.168.0.114:5000 [root@origin ~]# docker logout 192.168.0.114:15000 Removing login credentials for 192.168.0.114:15000拉取镜像
[root@origin ~]# docker pull 192.168.0.114:15000/hello-world Using default tag: latest latest: Pulling from hello-world 2db29710123e: Pull complete Digest: sha256:9ade9cc2e26189a19c2e8854b9c8f1e14829b51c55a630ee675a5a9540ef6ccf Status: Downloaded newer image for 192.168.0.114:15000/hello-world:latest 192.168.0.114:15000/hello-world:latest
至此,匿名拉取完成。
-
注意事项
使用Docker私服时,注意区分宿主仓库和组仓库;
组仓库:用于拉取镜像,会根据仓库优先级去拉取镜像
宿主仓库:主要用于推送本地镜像
所以拉取和推送的端口是不一样的

本文档详细介绍了如何使用Docker-compose搭建Nexus私有仓库,包括设置Docker镜像仓库、配置客户端、实现匿名拉取镜像,并提供了相关注意事项。通过Nexus,你可以管理并分发Docker镜像,类似于Maven私服的功能。
1009

被折叠的 条评论
为什么被折叠?



