如何使用docker-registry和登录名/密码?

问题描述 投票:8回答:2

我在localhost中有我的docker-registry,我可以用命令拉/推:docker push localhost:5000/someimage如何用docker push username@password:localhost:5000/someimage这样的命令推送它?

docker docker-registry
2个回答
22
投票

这个解决方案对我有用:首先我创建了一个文件夹注册表,我想在其中工作:

$ mkdir registry
$ cd registry/

现在我创建我的文件夹,我将在其中存储我的凭据

$ mkdir auth

现在我将在docker容器的帮助下创建一个htpasswd文件。此htpasswd文件将包含我的凭据和加密的passwd。

$ 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


2
投票

尝试在你的docker conf文件~/.docker/config.json中设置它

{
        "auths": {
                "https://localhost:5000/someimage": {
                        "auth": "username",
                        "email": "password"
                }
        }
}
© www.soinside.com 2019 - 2024. All rights reserved.