Docker注册表镜像未被使用。

14

当我尝试从我的本地镜像拉取图像时,它可以正常工作:

$ docker login -u docker -p mypassword nexus3.pleiade.mycomp.fr:5000
$ docker pull nexus3.pleiade.mycomp.fr:5000/hello-world
Using default tag: latest
latest: Pulling from **hello-world**
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for **nexus3.pleiade.mycomp.fr:5000/hello-world:latest**

但是,当我想将此注册表用作镜像时,它会被忽略,图像总是从web Docker hub中获取,而不是从我的本地镜像中获取:

$ ps -ef | grep docker
/usr/bin/dockerd -H fd:// --storage-driver=overlay2 --registry-mirror=https://nexus3.pleiade.mycomp.fr:5000

$ docker info
Registry Mirrors:
 https://nexus3.pleiade.mycomp.fr:5000/

$ docker rmi nexus3.pleiade.mycomp.fr:5000/hello-world

_

$ docker pull hello-world
Using default tag: latest
latest: Pulling from **library/hello-world**
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for **hello-world:latest**

我确定它没有使用我的镜像,因为当我取消代理设置时,它无法访问hello-world镜像。

这是Docker的bug吗?还是我漏掉了什么?

Docker信息(简要):

Server Version: 1.13.1
Storage Driver: overlay2
(...)
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.8.0-37-generic
Operating System: Ubuntu 16.10
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 15.67 GiB
(...)
Registry Mirrors:
 https://nexus3.pleiade.edf.fr:5000/

更新:

通过执行"journalctl -xe"命令,我看到了一些有用的信息:

level=error msg="尝试在错误后拉取下一个端点:获取 https://nexus3.pleiade.mycomp.fr:5000/v2/library/hello-world/manifests/latest 时出错:没有基本身份验证凭据"

这似乎与https://github.com/docker/docker/issues/20097有关,但解决方法不起作用:当我将--registry-mirror=https://nexus3.pleiade.mycomp.fr:5000替换为--registry-mirror=https://docker:password@nexus3.pleiade.mycomp.fr:5000时,我得到了完全相同的错误。

如果有影响的话,Nexus使用自签名证书,该证书已复制到/etc/docker/certs.d/nexus3.pleiade.mycomp.fr:5000/ca.crt,并且这允许通过“docker login”进行登录。


https://nexus3.pleiade.mycomp.fr:5000 是否是内部托管的?如果是,则尝试添加 no_proxy=nexus3.pleiade.mycomp.fr - Nehal J Wani
我已经尝试过完全不使用代理。如果是代理问题,错误就不会是“获取https://nexus3.pleiade.mycomp.fr:5000/v2/library/hello-world/manifests/latest时出错:没有基本身份验证凭据”。 - Tristan
1
可能是主要功能上的另一个Docker错误:https://github.com/docker/docker/issues/30880。解决方法是设置一个https反向代理,设置一个硬编码的身份验证标头。 - Tristan
抱歉打扰了一个旧的线程,但是如果有其他人犯了我的错误,请确保在您的daemon.json中不要声明docker-registries两次。 =/ - duct_tape_coder
5个回答

6
这是一个Docker的bug: https://github.com/docker/docker/issues/30880 解决方法是设置一个HTTPS反向代理,并设置一个硬编码的身份验证头。
这里有一个来自Felipe C.的示例配置:
在Nginx Docker配置中,添加:
proxy_set_header Authorization "Basic a2luZzppc25ha2Vk";

完整示例:

server {
    listen *:443 ssl http2;
    server_name docker.domain.blah.net;
    ssl on;
    include ssl/domain.blah.net.conf;
    # allow large uploads of files - refer to nginx documentation
    client_max_body_size 0;
    chunked_transfer_encoding on;
    location / {
        proxy_pass http://127.0.0.1:8083/;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Authorization "Basic YWRtaW46YWRtaW4xMjM=";

        #proxy_set_header X-Forwarded-Proto "https";
    }
}

server {
    listen *:80;
    server_name docker.domain.blah.net;
    return 301 https://$server_name$request_uri;
}

最新的 Nexus 版本支持像 "Docker Barer Token Realm" 这样的东西,因此这个解决方法应该可以工作,但可能还有其他解决方案。当然,还有其他选择,比如使用 Kubernetes 或 OpenShift,允许将私有注册表指定为 '默认注册表'。这取决于具体的用例。 - gavioto

1
另一种方法是注销其他服务器的Docker登录,并启用注册表配置“允许匿名Docker拉取(需要Docker Bearer Token Realm)”。

0

我可能有点晚到这个派对,但我希望这能帮助到某些人。我遇到了同样的问题,在nexus日志中出现了认证错误。

事实证明,我需要在我的nexus存储库设置中启用匿名docker拉取。

enter image description here

在这样做之后,还要检查安全性->领域下的 Docker Bearer Token Realm 是否处于活动状态并具有高优先级。

enter image description here


1
我尝试允许所有匿名的docker pull,但仍然无法工作。 - navono

0

我成功地添加了 /etc/docker/daemon.json 文件:

{
    "registry-mirrors": [ "nexus3.pleiade.mycomp.fr" ],
    "max-concurrent-downloads": 20
}

有趣,但是你应该告诉我们更多(例如使用哪个操作系统,哪个Docker版本等)。在我的操作系统(Ubuntu)上,我无法使用/etc/docker/daemon.json来自定义systemd服务。 - Tristan
3
这个解决方案不可能有效,因为已经有人报告了同样的问题,而我正在使用它,仍然遇到“没有基本身份验证凭据”的问题。目前似乎nginx解决方案是唯一可行的解决方法 - 不幸的是。 - Pierluigi Vernetto

-5

您可以在 URL 中添加基本身份验证,这对我有效。类似如下:

https://username:password@nexus3.pleiade.mycomp.fr:5000

2
Docker不允许这样做,它会报错invalid mirror: username/password not allowed in URI - apr_1985
2
这种在URL中明文传输用户名和密码的行为应该被W3C禁止并受到惩罚。摇头 - Stefan Höltker

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接