
代码示例:
搭建Docker私有化仓库有多种方法,以下是几种常见的搭建方式的详细例子:
-
使用官方Registry镜像搭建私有仓库:
- 拉取Registry镜像并运行:
docker pull registry:2 docker run -d -p 5000:5000 --name my-registry registry:2 - 推送镜像到私有仓库:
docker tag <IMAGE_ID> localhost:5000/my-image:latest docker push localhost:5000/my-image:latest - 从私有仓库拉取镜像:
docker pull localhost:5000/my-image:latest - 使用
docker-compose启动私有仓库
- 拉取Registry镜像并运行:
-
使用Harbor搭建企业级私有仓库:
- 安装Docker和Docker Compose。
- 下载Harbor安装包并解压:
wget https://github.com/goharbor/harbor/releases/download/v2.9.0/harbor-online-installer-v2.9.0.tgz - 修改Harbor配置文件
harbor.yml,设置hostname、http/https等。 - 执行安装脚本
./install.sh启动Harbor。 - 访问Harbor Web UI进行项目管理和用户管理。
- 使用Docker命令与Harbor交互,包括登录、推送和拉取镜像:
docker login <Harbor_IP> docker push <Harbor_IP>/myproject/my-image:tag docker pull <Harbor_IP>/myproject/my-image:tag - Harbor提供了基于角色的访问控制、镜像复制、AD/LDAP支持等特性。
-
使用GitLab Container Registry:
- 安装GitLab并启用Container Registry:
vim /etc/gitlab/gitlab.rb registry_external_url 'https://registry.mycompany.com' gitlab-ctl reconfigure - 登录GitLab Container Registry:
docker login registry.mycompany.com - 推送和拉取镜像:
docker tag <IMAGE_ID> registry.mycompany.com/mygroup/myproject/my-image:latest docker push registry.mycompany.com/mygroup/myproject/my-image:latest docker pull registry.mycompany.com/mygroup/myproject/my-image:latest
- 安装GitLab并启用Container Registry:
-
配置Docker信任私有仓库地址:
- 编辑
/etc/docker/daemon.json,添加私有仓库地址:{ "insecure-registries": ["http://192.168.138.100:8080"] } - 重启Docker服务:
systemctl daemon-reload systemctl restart docker - 推送和拉取镜像:
docker tag nginx:latest 192.168.150.101:8080/nginx:1.0 docker push 192.168.150.101:8080/nginx:1.0 docker pull 192.168.150.101:8080/nginx:1.0
- 编辑
以上是几种常见的搭建Docker私有化仓库的方法,可以根据具体需求和环境选择合适的搭建方式。
喜欢本文,请点赞、收藏和关注!
998

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



