配置registry加载身份验证
root@server01 ~]# yum -y install httpd-tools 安装加密工具httpd-tools [root@server01 myregistry]# pwd /myregistry [root@server01 myregistry]# mkdir registry-auth 创建存放验证密钥目录 [root@server01 myregistry]# htpasswd -Bbn ljj 123456 > /myregistry/registry-auth/htpasswd 配置registry身份验证数据库 "-Bbn”参数解释:B强制密码加密;b在命令中输入密码,不提示输入密码;n不更新密钥文件 [root@server01 myregistry]# cat registry-auth/htpasswd ljj:$2y$05$MhrXtmYlwqZ7.294TskEh.8zjNT9nZoyH5HYfy069Sh3ISaYQNjH2 [root@server01 registry-auth]# docker run -d -p 5000:5000 --restart=always -v /myregistry/registry-auth/:/auth/ -v /myregistry/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:2
[root@server01 ~]# docker tag nginx:latest 192.168.0.220:5000/nginx:v1.0 #修改镜像标签
[root@server01 ~]# docker login 192.168.0.220:5000 #登录registry仓库 Username: ljj 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@server01 ~]#
[root@server01 ~]# docker push 192.168.0.220:5000/nginx:v1.0 #上传镜像 The push refers to repository [192.168.0.220:5000/nginx] 85fcec7ef3ef: Mounted from centos 3e5288f7a70f: Mounted from centos 56bc37de0858: Mounted from centos 1c91bf69a08b: Mounted from centos cb42413394c4: Mounted from centos v1.0: digest: sha256:0b159cd1ee1203dad901967ac55eee18c24da84ba3be384690304be93538bea8 size: 1362
网页端访问:http://192.168.0.220:5000/v2/_catalog