Docker私有仓库如何实现Registry部署
发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,小编这次要给大家分享的是Docker私有仓库如何实现Registry部署,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。随着docker使用的镜像越来越多,就需要
千家信息网最后更新 2026年11月03日Docker私有仓库如何实现Registry部署
小编这次要给大家分享的是Docker私有仓库如何实现Registry部署,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。
随着docker使用的镜像越来越多,就需要有一个保存镜像的地方,这就是仓库。目前常用的两种仓库:公共仓库和私有仓库。最方便的就是使用公共仓库上传和下载,下载公共仓库的镜像是不需要注册的,但是上传时,是需要注册的。
私有仓库最常用的就是Registry、Harbor两种,那接下来详细介绍如何搭建registry私有仓库,Harbor将在下一篇博文部署。
一、部署Registry私有仓库
案例描述
两台CentOS7.4,一台为Docker私有仓库;另一台为Docker客户端,测试使用;
两台服务器都需要安装Docker服务,请参考博文:安装Docker.v19版本
1、配置registry私有仓库
[root@centos01 ~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf [root@centos01 ~]# sysctl -p net.ipv4.ip_forward = 1[root@centos01 ~]# vim /etc/docker/daemon.json {"registry-mirrors":["https://6kx4zyno.mirror.aliyuncs.com"]} [root@centos01 ~]# systemctl reload docker [root@centos01 ~]# docker search registry [root@centos01 ~]# docker run -d -p 5000:5000 --name registry --restart=always -v /opt/registry:/var/lib/registry registry [root@centos01 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESa7773d77b8a3 registry "/entrypoint.sh /etc…" 50 seconds ago Up 46 seconds 0.0.0.0:5000->5000/tcp registry[root@centos01 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZEregistry latest 708bc6af7e5e 3 months ago 25.8MBtomcat latest 1b6b1fe7261e 5 days ago 647MBhub.c.163.com/public/centos 6.7-tools b2ab0ed558bb 3 years ago 602MB[root@centos01 ~]# vim /etc/docker/daemon.json {"registry-mirrors":["https://6kx4zyno.mirror.aliyuncs.com"],"insecure-registries":["192.168.100.10:5000"] }[root@centos01 ~]# systemctl reload docker 2、上传镜像到registry私有仓库
[root@centos01 ~]# docker tag hub.c.163.com/public/centos:6.7-tools 192.168.100.10:5000/image/centos:6.7 [root@centos01 ~]# docker push 192.168.100.10:5000/image/centos:6.7
二、配置Docker客户端访问私有仓库
[root@centos02 ~]# vim /etc/docker/daemon.json {"registry-mirrors":["https://6kx4zyno.mirror.aliyuncs.com"],"insecure-registries":["192.168.100.10:5000"] }[root@centos02 ~]# systemctl restart docker [root@centos02 ~]# docker pull 192.168.100.10:5000/image/centos:6.7 [root@centos02 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE192.168.100.10:5000/image/centos 6.7 b2ab0ed558bb 3 years ago 602MB至此registry私有仓库已经搭建完成,但是现在存在一个问题,如果这也部署的话企业内部所有人员皆可访问我们的私有仓库,为了安全起见,接下来为registry添加一个身份验证,只有通过了身份验证才可以上传或者下载私有仓库中的镜像。
三、配置registry加载身份验证
[root@centos01 ~]# yum -y install httpd-tools [root@centos01 ~]# mkdir /opt/registry-auth [root@centos01 ~]# htpasswd -Bbn bob pwd@123 > /opt/registry-auth/htpasswd [root@centos01 ~]# docker run -d -p 5000:5000 --restart=always \-v /opt/registry-auth/:/auth/ \-v /opt/registry:/var/lib/registry --name registry-auth -e "REGISTRY_AUTH=htpasswd" \-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \-e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" registry [root@centos01 ~]# docker tag tomcat:latest 192.168.100.10:5000/image/tomcat:1.0 [root@centos01 ~]# docker push 192.168.100.10:5000/image/tomcat:1.0 no basic auth credentials[root@centos01 ~]# docker login 192.168.100.10:5000 Username: bob Password: ……………… Login Succeeded [root@centos01 ~]# docker push 192.168.100.10:5000/image/tomcat:1.0 The push refers to repository [192.168.100.10:5000/image/tomcat]b0ac242ce8d3: Pushed5e71d8e4cd3d: Pushedeb4497d7dab7: Pushedbfbfe00b44fc: Pushedd39111fb2602: Pushed155d997ed77c: Pushed88cfc2fcd059: Pushed760e8d95cf58: Pushed7cc1c2d7e744: Pushed8c02234b8605: Pushed1.0: digest: sha256:55b41e0290d32d6888aee2e9a15f03cc88d2f49d5ad68892c54b9527d0ed181c size: 2421[root@centos02 ~]# docker pull 192.168.100.10:5000/image/tomcat:1.0 Error response from daemon: Get http://192.168.100.10:5000/v2/image/tomcat/manifests/1.0: no basic auth credentials[root@centos02 ~]# docker login 192.168.100.10:5000 Username: bob Password: Login Succeeded [root@centos02 ~]# docker pull 192.168.100.10:5000/image/tomcat:1.0 1.0: Pulling from image/tomcat376057ac6fa1: Pull complete5a63a0a859d8: Pull complete496548a8c952: Pull complete2adae3950d4d: Pull complete0a297eafb9ac: Pull complete09a4142c5c9d: Pull complete9e78d9befa39: Pull complete18f492f90b9c: Pull complete7834493ec6cd: Pull complete216b2be21722: Pull completeDigest: sha256:55b41e0290d32d6888aee2e9a15f03cc88d2f49d5ad68892c54b9527d0ed181cStatus: Downloaded newer image for 192.168.100.10:5000/image/tomcat:1.0192.168.100.10:5000/image/tomcat:1.0[root@centos02 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE192.168.100.10:5000/image/tomcat 1.0 1b6b1fe7261e 5 days ago 647MB192.168.100.10:5000/image/centos 6.7 b2ab0ed558bb 3 years ago 602MB
看完这篇关于Docker私有仓库如何实现Registry部署的文章,如果觉得文章内容写得不错的话,可以把它分享出去给更多人看到。
仓库
私有
镜像
就是
文章
身份
配置
验证
接下来
内容
客户
客户端
常用
服务
不错
安全
人员
企业
兴趣
内容丰富
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
上海卓越科技互联网
华服互联网科技怎么样
科技金融是不是互联网金融
万易互联网科技有限公司
科技互联网公司logo
互联网和高科技公司
北京华百购互联网科技有限公司
阿里互联网科技公司
南山科技园互联网公司有哪些
互联网经济与金融科技
语蝶互联网科技有限公司
深圳市优智互联网科技有限公司
浙南科技城互联网大厦建设工程
风投北京互联网科技
吉林省码上互联网科技电话
版纳互联网科技选哪家
广州三三互联网科技有限公司
好易买互联网科技
保山浩联互联网科技有限公司
北京瑞云互联网科技有限公司
哈尔滨大商圈互联网科技有限公司
互联网与科技发展
有木互联网科技
西藏七维空间互联网科技有限公司
互联网企业和科技型企业
中国航天科技大学国际工业互联网
深圳互联网科技的发展
深圳无忧互联网科技
互联网科技收购价值
优雇互联网科技有限公司