如何使用docker-registry与login名/密码?

我有我的dockerregistry本地主机,我可以拉/推命令: docker push localhost:5000/someimage我可以推它像docker push username@password:localhost:5000/someimage

这个解决scheme为我工作:首先,我创build了一个文件夹registry,我想在其中工作:

 $ mkdir registry $ cd registry/ 

现在我创build我的文件夹,我将存储我的凭据

 $ mkdir auth 

现在我将在Docker容器的帮助下创build一个htpasswd文件。 这个htpasswd文件将包含我的凭据和我的encryption密码。

 $ docker run --entrypoint htpasswd registry:2 -Bbn myuser mypassword > auth/htpasswd 

核实

 $ cat auth/htpasswd myuser:$2y$05$8IpPEG94/u.gX4Hn9zDU3.6vru2rHJSehPEZfD1yyxHu.ABc2QhSa 

凭据很好。 现在我必须将我的凭据添加到我的registry中。 这里我将在我的容器中安装我的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 

testing:

 $ docker push localhost:5000/busybox The push refers to a repository [localhost:5000/busybox] 8ac8bfaff55a: Image push failed unauthorized: authentication required 

authentication

 $ 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=" } } 

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

 { "auths": { "https://localhost:5000/someimage": { "auth": "username", "email": "password" } } }