1.registry的安装
关于docker registry的安装,可以说简单的不能再简单了,docker run一个容器就好了,也就是一条命令的事
docker run -d -p : --restart=always --name registry -v /opt/myregistry:/var/lib/registry registry
2.上传镜像
上次镜像其实就两步,给镜像打tag和push上传
2.1 打tag
格式:docker tag 源镜像名字:版本 私有仓库地址/镜像名字:版本
例如:
docker tag centos:6.10 10.0.0.11:5000/centos:6.10
2.2 push上传
docker push 10.0.0.11:5000/centos:6.10 默认上传肯定报错! The push refers to a repository [10.0.0.11:5000/centos:6.10] Get https://10.0.0.11:5000/v1/_ping: http: server gave HTTP response to HTTPS client 解决办法: 把自己的私有镜像仓库加到信任的仓库列表中。 vi /etc/docker/daemon.json { "registry-mirrors": ["https://registry.docker-cn.com"], "insecure-registries": ["10.0.0.11:5000"] } systemctl restart docker 然后重新push
3.下载镜像
下载镜像就一条命令docker pull 例如: docker pull 10.0.0.11:5000/centos:6.10 默认下载肯定报错! Trying to pull repository 10.0.0.11:5000/centos ... Get https://10.0.0.11:5000/v1/_ping: http: server gave HTTP response to HTTPS client 解决办法同上传
4.查看镜像列表
使用浏览器访问:
http://10.0.0.11:5000/v2/_catalog
5.查看镜像的版本
下面我已nginx为例
http://10.0.0.11:5000/v2/nginx/tags/list
6.删除镜像
1)进入docker registry的容器中 docker exec -it registry /bin/sh 2) 删除repo rm -fr /var/lib/registry/docker/registry/v2/repositories/nginx 3) 清楚掉blob registry garbage-collect /etc/docker/registry/config.yml
7.带认证的registry
yum install httpd-tools -y mkdir /opt/registry-var/auth/ -p htpasswd -Bbn oldboy 123456 >> /opt/registry-var/auth/htpasswd 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 提示:上传下载镜像都需要登陆哦 docker login 10.0.0.11:5000 oldboy 123456 docker logout 10.0.0.11:5000登出