docker registry 私有仓库的搭建过程

这篇文章主要介绍了docker registry 私有仓库,私有仓库最常用的就是Registry、Harbor两种,那接下来详细介绍如何搭建registry私有仓库,感兴趣的朋友跟随小编一起看看吧

摘要

随着docker使用的镜像越来越多,就需要有一个保存镜像的地方,这就是仓库。目前常用的两种仓库:公共仓库和私有仓库。最方便的就是使用公共仓库上传和下载,下载公共仓库的镜像是不需要注册的,但是上传时,是需要注册的。私有仓库最常用的就是Registry、Harbor两种,那接下来详细介绍如何搭建registry私有仓库。

一、环境准备

两台CentOS7.4,一台为Docker私有仓库;另一台为Docker客户端,测试使用;

二、配置registry私有仓库

 #   echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf  sysctl -p net.ipv4.ip_forward = 1  vim /etc/docker/daemon.json  {"registry-mirrors":["https://6kx4zyno.mirror.aliyuncs.com"]}  systemctl reload docker  docker search registry docker pull registry  docker run -d -p 5000:5000 --name registry --restart=always -v /opt/registry:/var/lib/registry registry  docker ps  docker images  vim /etc/docker/daemon.json {"registry-mirrors":["https://6kx4zyno.mirror.aliyuncs.com"], "insecure-registries":["192.168.100.10:5000"]   }  systemctl reload docker docker info

三、上传与下载镜像

# 给镜像打标签 docker tag mysql 192.168.25.140:5000/mysql # 上传的镜像 docker push 192.168.25.140:5000/mysql  vim /etc/docker/daemon.json {"registry-mirrors":["https://6kx4zyno.mirror.aliyuncs.com"], "insecure-registries":["192.168.100.10:5000"]   }  systemctl restart docker  docker pull 192.168.25.140:5000/mysql docker images 

四、配置registry加载身份验证

但是现在存在一个问题,如果这也部署的话企业内部所有人员皆可访问我们的私有仓库,为了安全起见,接下来为registry添加一个身份验证,只有通过了身份验证才可以上传或者下载私有仓库中的镜像。

 yum -y install httpd-tools  mkdir /opt/registry-auth  htpasswd -Bbn bob pwd@123 > /opt/registry-auth/htpasswd  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  docker tag tomcat:latest 192.168.100.10:5000/image/tomcat:1.0 docker push 192.168.100.10:5000/image/tomcat:1.0  no basic auth credentials  docker login 192.168.100.10:5000 Username: bob    Password:     docker push 192.168.100.10:5000/image/tomcat:1.0  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  docker login 192.168.100.10:5000 Username: bob   Password:      docker pull 192.168.100.10:5000/image/tomcat:1.0  docker images 

五、 docker registry 私有仓库查询、删除

修改tag (以hello-world为例)

拉取镜像 docker pull hello-world 修改镜像 docker tag  hello-world  hub.test.com:5000/hello-world:1.0 上传、删除、再下载镜像,删除后能下载成功 docker images docker push  hub.test.com:5000/hello-world:1.0 docker rmi hub.test.com:5000/hello-world:1.0 docker images docker pull  hub.test.com:5000/hello-world:1.0 docker images

 查看仓库镜像

curl hub.test.com:5000/v2/_catalog

registry开启删除

 #查看默认配置 docker exec -it  registry sh -c 'cat /etc/docker/registry/config.yml' #开启删除(添加  delete: enabled: true) docker exec -it  registry sh -c "sed -i '/storage:/a\  delete:' /etc/docker/registry/config.yml" docker exec -it  registry sh -c "sed -i '/delete:/a\    enabled: true' /etc/docker/registry/config.yml" #重启 docker restart registry

查询、删除镜像 

#查询镜像 curl  <仓库地址>/v2/_catalog #查询镜像tag(版本) curl  <仓库地址>/v2/<镜像名>/tags/list #删除镜像API curl -I -X DELETE "<仓库地址>/v2/<镜像名>/manifests/<镜像digest_hash>" #获取镜像digest_hash curl  <仓库地址>/v2/<镜像名>/manifests/ \ --header "Accept: application/vnd.docker.distribution.manifest.v2+json"

博文参考

https://www.0133.cn/article/187864.htm

安装docker registry - MartinEDM

到此这篇关于docker registry 私有仓库的文章就介绍到这了,更多相关docker registry 私有仓库内容请搜索0133技术站以前的文章或继续浏览下面的相关文章希望大家以后多多支持0133技术站!

以上就是docker registry 私有仓库的搭建过程的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 站长技巧