我使用以下方法设置了一个不安全的私人注册表:
[root@docker-regi ~]#docker run --entrypoint htpasswd registry:2 -Bbn myuser mypassword > /auth/htpasswd
[root@docker-regi ~]#docker run -d -p 5000:5000 --restart=always --name registry_auth -v `pwd`/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" registry:2
但尝试登录时:
[root@docker-remote ~]# !748
docker login -u myuser -p mypassword 192.168.122.190:5000
Error response from daemon: login attempt to http://192.168.122.190:5000/v2/ failed with status: 400 Bad Request
[root@docker-remote ~]#
提到https://docs.docker.com/registry/deploying/#native-basic-auth&&https://github.com/docker/distribution/issues/842
答案1
在第一个命令中,你将 htpasswd 写出为:
/auth/
然后你安装了:
`pwd`/auth
因此这些目录不匹配,你实际上从未挂载过 htpassswd 文件
如果你写出auth/htpasswd
它会起作用,因为它正在写入你当前的目录,而不是/
以下对我来说非常有效:
mkdir auth
docker run --entrypoint htpasswd registry:2 -Bbn myuser mypassword > auth/htpasswd
docker run -d -p 5000:5000 --restart=always --name registry_auth -v `pwd`/auth:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" registry:2
docker login -u myuser -p mypassword localhost:5000
返回:
Login Succeeded