美文网首页
docker私有仓库registry的使用

docker私有仓库registry的使用

作者: zwb_jianshu | 来源:发表于2019-07-24 16:45 被阅读0次
    1. registry的安装
    关于docker registry的安装,可以说简单的不能再简单了,docker run一个容器就好了,也就是一条命令的事
    
    docker run -d -p 5000:5000 --restart=always --name registry -v /opt/myregistry:/var/lib/registry registry
    
    1. 上传镜像
    上传镜像其实就两步,给镜像打tag和push上传
    
    1. 打tag
    格式:docker tag 源镜像名字:版本 私有仓库地址/镜像名字:版本
    例如:
    docker tag centos:6.10 10.0.0.11:5000/centos:6.10
    
    1. 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 
    解决办法:
    把自己的私有镜像仓库加到信任的仓库列表中。
    vim /etc/docker/daemon.json
    {
    "registry-mirrors": ["https://registry.docker-cn.com"],
    "insecure-registries": ["10.0.0.11:5000"]
    }
    systemctl restart docker
    然后重新push
    
    1. 下载镜像
    下载镜像就一条命令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 
    解决办法同上传
    
    1. 查看镜像列表
    使用浏览器访问:
    http://10.0.0.11:5000/v2/_catalog
    
    image
    1. 查看镜像的版本
    下面我已nginx为例
    http://10.0.0.11:5000/v2/nginx/tags/list
    
    image
    1. 删除镜像
    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
    
    1. 带认证的registry
    yum install httpd-tools -y
    mkdir /opt/registry-var/auth/ -p
    htpasswd -Bbn zwb 123456 >> /opt/registry-var/auth/htpasswd
    docker run -d -p 5000:5000 --restart=always  -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
    zwb
    123456
    docker logout 10.0.0.11:5000登出
    测试:
    [root@docker01 ~]# docker login  10.0.0.11:5000
    Username: zwb
    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@docker01 ~]# docker logout 10.0.0.11:5000
    Removing login credentials for 10.0.0.11:5000
    

    相关文章

      网友评论

          本文标题:docker私有仓库registry的使用

          本文链接:https://www.haomeiwen.com/subject/aqnxrctx.html