docker(15):docker的私有仓库registry

docker(15):docker的私有仓库registry

https://www.qstack.com.cn/archives/350.html

https://www.cnblogs.com/luoahong/p/10284186.html

1  运行docker私有仓库

1.1 安装registry

docker run -d -p 5000:5000 --restart=always --name registry -v /opt/myregistry:/var/lib/registry registry

 

当容器启动完成,私有仓库就可以使用了

[root@docker-136 ~]# docker images | grep registry
registry                        latest              f32a97de94e1        5 months ago        25.8MB
[root@docker-136 ~]# docker ps -a| grep registry
d61015680b28        registry                               "/entrypoint.sh /etc…"   43 seconds ago      Up 40 seconds       0.0.0.0:5000->5000/tcp        registry
[root@docker-136 ~]#

2  上传镜像到私有仓库

2.1 给要上传的镜像打tag

[root@docker-136 ~]# docker images | grep centos-7
centos-7-ssh-nginx                      v1                  93af120d6d0b        4 days ago          413MB
[root@docker-136 ~]#
[root@docker-136 ~]# docker image tag centos-7-ssh-nginx:v1 192.168.0.136:5000/centos-7-ssh-nginx:v1
[root@docker-136 ~]# docker images | grep centos-7
192.168.0.136:5000/centos-7-ssh-nginx   v1                  93af120d6d0b        4 days ago          413MB
centos-7-ssh-nginx                      v1                  93af120d6d0b        4 days ago          413MB
[root@docker-136 ~]#

 

2.2 上传

[root@docker-136 ~]# docker push 192.168.0.136:5000/centos-7-ssh-nginx
The push refers to repository [192.168.0.136:5000/centos-7-ssh-nginx]
Get https://192.168.0.136:5000/v2/: http: server gave HTTP response to HTTPS client
[root@docker-136 ~]#

 

2.3 解决报错再次上传

 

[root@docker-136 ~]# cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://6ek3bw21.mirror.aliyuncs.com"],
   "insecure-registries": ["192.168.0.136:5000"]
}
[root@docker-136 ~]#  systemctl restart docker   
[root@docker-136 ~]# docker push 192.168.0.136:5000/centos-7-ssh-nginx
The push refers to repository [192.168.0.136:5000/centos-7-ssh-nginx]
a9a815c886b9: Pushed 
d69483a6face: Pushed 
v1: digest: sha256:2621e4353582ea953fc7974e100d84c117ecf1e59ca389430aa2c40267b49ddf size: 741
[root@docker-136 ~]#
[root@docker-136 repositories]# pwd
/opt/myregistry/docker/registry/v2/repositories  #上传镜像的位置
[root@docker-136 repositories]# ls
centos-7-ssh-nginx
[root@docker-136 repositories]#

 

3  下载镜像

 

[root@docker-136 repositories]# docker images | grep centos-7
192.168.0.136:5000/centos-7-ssh-nginx   v1                  93af120d6d0b        5 days ago          413MB
centos-7-ssh-nginx                      v1                  93af120d6d0b        5 days ago          413MB
[root@docker-136 repositories]# docker image rm 192.168.0.136:5000/centos-7-ssh-nginx:v1 
Untagged: 192.168.0.136:5000/centos-7-ssh-nginx:v1
Untagged: 192.168.0.136:5000/centos-7-ssh-nginx@sha256:2621e4353582ea953fc7974e100d84c117ecf1e59ca389430aa2c40267b49ddf
[root@docker-136 repositories]# docker images | grep centos-7                         
centos-7-ssh-nginx              v1                  93af120d6d0b        5 days ago          413MB
[root@docker-136 repositories]# docker pull 192.168.0.136:5000/centos-7-ssh-nginx:v1
v1: Pulling from centos-7-ssh-nginx
Digest: sha256:2621e4353582ea953fc7974e100d84c117ecf1e59ca389430aa2c40267b49ddf
Status: Downloaded newer image for 192.168.0.136:5000/centos-7-ssh-nginx:v1
192.168.0.136:5000/centos-7-ssh-nginx:v1
[root@docker-136 repositories]# docker images | grep centos-7                       
192.168.0.136:5000/centos-7-ssh-nginx   v1                  93af120d6d0b        5 days ago          413MB
centos-7-ssh-nginx                      v1                  93af120d6d0b        5 days ago          413MB
[root@docker-136 repositories]#

 

4  查看镜像列表和版本

列表 http://192.168.0.136:5000/v2/_catalog 

 

 版本 http://192.168.0.136:5000/v2/centos-7-ssh-nginx/tags/list

 

 

5  删除镜像

#1)进入docker registry的容器中 
docker exec -it registry /bin/sh 
#2) 删除repo 
rm -fr /var/lib/registry/docker/registry/v2/repositories/ centos-7-ssh-nginx
#3) 清楚掉blob 
registry garbage-collect /etc/docker/registry/config.yml 

 

6  带base认证的私有仓库

yum install httpd-tools -y
mkdir /opt/registry-var/auth/ -p
htpasswd -Bbn admin 123456 >> /opt/registry-var/auth/htpasswd
#关闭之前的registry
docker run -d -p 5000:5000 -v /opt/registry-var/auth/:/auth/ -v /opt/myregistry:/var/lib/registry -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry 

 

[root@docker-136 ~]# docker ps -a 
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS                        PORTS                    NAMES
d61015680b28        registry                               "/entrypoint.sh /etc…"   34 minutes ago      Up 16 minutes                 0.0.0.0:5000->5000/tcp   registry
c0157be0d8da        zabbix/zabbix-web-nginx-mysql:latest   "docker-entrypoint.sh"   About an hour ago   Exited (0) 29 minutes ago                              zabbix-web-nginx-mysql
fbb8488ecdd4        zabbix/zabbix-server-mysql:latest      "/sbin/tini -- /usr/…"   About an hour ago   Exited (1) 29 minutes ago                              zabbix-server-mysql
30ea677e88a2        zabbix/zabbix-java-gateway:latest      "docker-entrypoint.sh"   About an hour ago   Exited (137) 29 minutes ago                            zabbix-java-gateway
a008337eb10c        mysql:5.7                              "docker-entrypoint.s…"   About an hour ago   Exited (0) 29 minutes ago                              mysql-server
[root@docker-136 ~]# docker stop d61015680b28
d61015680b28
[root@docker-136 ~]# docker run -d -p 5000:5000 -v /opt/registry-var/auth/:/auth/ -v /opt/myregistry:/var/lib/registry -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry 
22b6f523211438d927700910e1caa93c163250745134b9b1443ac0bdbce5f229
[root@docker-136 ~]# docker ps -a| grep registry
22b6f5232114        registry                               "/entrypoint.sh /etc…"   30 seconds ago      Up 28 seconds                 0.0.0.0:5000->5000/tcp   kind_mclaren
d61015680b28        registry                               "/entrypoint.sh /etc…"   35 minutes ago      Exited (2) 44 seconds ago                              registry

 

 

 

提示:上传下载镜像都需要登陆

[root@docker-136 ~]# docker images | grep centos-7                            
centos-7-ssh-nginx              v1                  93af120d6d0b        5 days ago          413MB
[root@docker-136 ~]# docker pull 192.168.0.136:5000/centos-7-ssh-nginx:v1   
Error response from daemon: Get http://192.168.0.136:5000/v2/centos-7-ssh-nginx/manifests/v1: no basic auth credentials
[root@docker-136 ~]# docker login 192.168.0.136: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
[root@docker-136 ~]# docker pull 192.168.0.136:5000/centos-7-ssh-nginx:v1 
v1: Pulling from centos-7-ssh-nginx
Digest: sha256:2621e4353582ea953fc7974e100d84c117ecf1e59ca389430aa2c40267b49ddf
Status: Downloaded newer image for 192.168.0.136:5000/centos-7-ssh-nginx:v1
192.168.0.136:5000/centos-7-ssh-nginx:v1
[root@docker-136 ~]# docker images | grep centos-7                        
192.168.0.136:5000/centos-7-ssh-nginx   v1                  93af120d6d0b        5 days ago          413MB
centos-7-ssh-nginx                      v1                  93af120d6d0b        5 days ago          413MB
[root@docker-136 ~]#

 

posted on 2019-08-13 17:20  光阴8023  阅读(356)  评论(0编辑  收藏  举报