我在 localhost 中有我的 docker-registry,我可以使用以下命令拉/推:docker push localhost:5000/someimage
如何使用 docker push username@password:localhost:5000/someimage
之类的命令推送它?
最佳答案
这个解决方案对我有用: 首先,我创建了一个我想在其中工作的文件夹注册表:
$ mkdir registry
$ cd registry/
现在我创建我的文件夹,我将在其中存储我的凭据
$ mkdir auth
现在我将在 docker 容器的帮助下创建一个 htpasswd 文件。 这个 htpasswd 文件将包含我的凭据和我的加密密码。
$ docker run --entrypoint htpasswd registry:2 -Bbn myuser mypassword > auth/htpasswd
验证
$ cat auth/htpasswd
myuser:$2y$05$8IpPEG94/u.gX4Hn9zDU3.6vru2rHJSehPEZfD1yyxHu.ABc2QhSa
凭据很好。现在我必须将我的凭据添加到我的注册表中。在这里,我将在我的容器中挂载我的 auth 目录:
docker run -d -p 5000:5000 --restart=always --name registry_private -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 push localhost:5000/busybox
The push refers to a repository [localhost:5000/busybox]
8ac8bfaff55a: Image push failed
unauthorized: authentication required
验证
$ docker login localhost:5000
Username (): myuser
Password:
Login Succeeded
重试推送
$ docker push localhost:5000/busybox
The push refers to a repository [localhost:5000/busybox]
8ac8bfaff55a: Pushed
latest: digest: sha256:1359608115b94599e5641638bac5aef1ddfaa79bb96057ebf41ebc8d33acf8a7 size: 527
凭据保存在 ~/.docker/config.json 中:
cat ~/.docker/config.json
{
"auths": {
"localhost:5000": {
"auth": "bXl1c2VyOm15cGFzc3dvcmQ="
}
}
不要忘记在使用凭据时建议使用 https。
这里有一篇关于如何使用 TLS(采用这种方法的自签名证书)的博客:https://medium.com/@lvthillo/deploy-a-docker-registry-using-tls-and-htpasswd-56dd57a1215a
关于docker - 如何使用带有登录名/密码的 docker-registry?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38247362/