docker - 如何使用带有登录名/密码的 docker-registry?

标签 docker docker-registry

我在 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/

相关文章:

docker - 无法将Docker镜像推送到Openshift Origin Docker注册表

docker - 在 Windows 中从 bootdocker 登录到 docker hub 注册表时出现问题

linux - 我应该使用哪个 docker OS 基础镜像?

docker - Kubernetes - 如何制作简单的 Linux 容器镜像而无需永久运行应用程序

amazon-web-services - 如何从 Elastic Beanstalk 实例访问 S3 存储桶中的 docker 配置文件

docker run 注册表错误 301 响应缺少位置 header

docker - 从 Docker Registry API 下载私有(private)存储库 list

django - 无法使用 django-channels 连接到 websocket,docker 上的 nginx 作为服务

docker - 在容器重启之前保存 docker 容器日志文件

docker - Diff Docker注册表镜像