加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-16 03:41:04 所属栏目:安全 来源:网络整理
导读:我在localhost中有我的docker-registry,我可以用命令拉/推:docker push localhost:5000 / someimage 如何使用docker push username @ password:localhost:5000 / someimage等命令推送它? 最佳答案 这个解决方案对我有用: 首先,我创建了一个文件夹注册

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

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

$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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读