推送到本地 docker 注册表会导致连接重置错误

推送到本地 docker 注册表会导致连接重置错误

我正在尝试按照以下步骤创建一个私有的 Docker 注册表本指南。我已经下载并标记了一个 Ubuntu 映像并创建了一个注册表容器,现在我打算将其推送到我的注册表,但是当我调用时sudo docker push localhost:6000/Ubuntu我得到以下输出:

The push refers to a repository [localhost:6000/ubuntu] Put http://localhost:6000/v1/repositories/ubuntu/: http: can't write HTTP request on broken connection

我所能找到的只是“无法写入 HTTP 请求”错误是一个 Go 错误,但不幸的是,我找不到任何与如何在 Docker 中解决此问题相关的信息。我还尝试查找 Docker 命令的日志,以便尝试获取有关该问题的更多详细信息,但似乎日志仅适用于容器,而我没有在容器上运行它。

我该如何解决这个错误?

更新

我什么都没做任何改变后再次运行了该命令,却得到了不同的错误:

Put http://localhost:6000/v1/repositories/ubuntu/: read tcp [::1]:33417->[::1]:6000: read: connection reset by peer

更新2

再次,在不做任何更改的情况下运行它,现在得到:

Put http://localhost:6000/v1/repositories/ubuntu/: EOF

更新3

经过一番折腾之后,我发现我尝试推送到注册表的图像确实出现在我的 docker 图像列表中,但我似乎无法将其拉出。

更新4

经过一番折腾之后,我发现我分配给私人注册表的端口似乎只监听 IPV6,而不是 IPV4。根据git 线程,docker 似乎只在 IPV6 上监听,这是正常的,但在运行telnet localhostnetstat -ntlp和之后iptables -t nat -nxvL,我仍然没有看到任何迹象表明有任何迹象表明 127.0.0.1:6000 正在监听,这是我的注册表(仅作为容器运行)应该分配到的端口。相反,它似乎在监听 :::1:6000。

此外,因为这是被要求的,而且无论如何我都应该列出它:

user@devstack01:~$ sudo docker version
Client:
 Version:      1.10.3
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   20f81dd
 Built:        Thu Mar 10 15:54:52 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.10.3
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   20f81dd
 Built:        Thu Mar 10 15:54:52 2016
 OS/Arch:      linux/amd64

更新5

注册容器的日志:

time="2016-04-04T18:34:22Z" level=warning msg="No HTTP secret provided - generated random secret. This may cause problems with uploads if multiple registries are behind a load-balancer. To provide a shared secret, fill in http.secret in the configuration file or set the REGISTRY_HTTP_SECRET environment variable." go.version=go1.5.3 instance.id=25b8dd5a-f154-455b-84ad-3dd61ccf04e0 version=v2.3.1
time="2016-04-04T18:34:22Z" level=info msg="redis not configured" go.version=go1.5.3 instance.id=25b8dd5a-f154-455b-84ad-3dd61ccf04e0 version=v2.3.1
time="2016-04-04T18:34:22Z" level=info msg="Starting upload purge in 58m0s" go.version=go1.5.3 instance.id=25b8dd5a-f154-455b-84ad-3dd61ccf04e0 version=v2.3.1
time="2016-04-04T18:34:22Z" level=info msg="using inmemory blob descriptor cache" go.version=go1.5.3 instance.id=25b8dd5a-f154-455b-84ad-3dd61ccf04e0 version=v2.3.1
time="2016-04-04T18:34:22Z" level=info msg="listening on [::]:5000" go.version=go1.5.3 instance.id=25b8dd5a-f154-455b-84ad-3dd61ccf04e0 version=v2.3.1
time="2016-04-04T19:32:22Z" level=info msg="PurgeUploads starting: olderThan=2016-03-28 19:32:22.890256531 +0000 UTC, actuallyDelete=true"
time="2016-04-04T19:32:22Z" level=info msg="Purge uploads finished.  Num deleted=0, num errors=1"
time="2016-04-04T19:32:22Z" level=info msg="Starting upload purge in 24h0m0s" go.version=go1.5.3 instance.id=25b8dd5a-f154-455b-84ad-3dd61ccf04e0 version=v2.3.1
time="2016-04-05T13:54:59Z" level=warning msg="No HTTP secret provided - generated random secret. This may cause problems with uploads if multiple registries are behind a load-balancer. To provide a shared secret, fill in http.secret in the configuration file or set the REGISTRY_HTTP_SECRET environment variable." go.version=go1.5.3 instance.id=90882341-a150-4384-9434-b091aacdd68b version=v2.3.1
time="2016-04-05T13:54:59Z" level=info msg="redis not configured" go.version=go1.5.3 instance.id=90882341-a150-4384-9434-b091aacdd68b version=v2.3.1
time="2016-04-05T13:54:59Z" level=info msg="Starting upload purge in 59m0s" go.version=go1.5.3 instance.id=90882341-a150-4384-9434-b091aacdd68b version=v2.3.1
time="2016-04-05T13:54:59Z" level=info msg="using inmemory blob descriptor cache" go.version=go1.5.3 instance.id=90882341-a150-4384-9434-b091aacdd68b version=v2.3.1
time="2016-04-05T13:54:59Z" level=info msg="listening on [::]:5000" go.version=go1.5.3 instance.id=90882341-a150-4384-9434-b091aacdd68b version=v2.3.1
time="2016-04-05T14:53:59Z" level=info msg="PurgeUploads starting: olderThan=2016-03-29 14:53:59.133142744 +0000 UTC, actuallyDelete=true"
time="2016-04-05T14:53:59Z" level=info msg="Purge uploads finished.  Num deleted=0, num errors=1"
time="2016-04-05T14:53:59Z" level=info msg="Starting upload purge in 24h0m0s" go.version=go1.5.3 instance.id=90882341-a150-4384-9434-b091aacdd68b version=v2.3.1

当我尝试将图像推送到我的注册表时,Docker 守护程序的调试日志:

DEBU[0037] Calling POST /v1.22/images/localhost:6000/hello-world/push
DEBU[0037] POST /v1.22/images/localhost:6000/hello-world/push?tag=
DEBU[0037] Trying to push localhost:6000/hello-world to https://localhost:6000 v2
DEBU[0037] Error getting v2 registry: Get https://localhost:6000/v2/: read tcp [::1]:33560->[::1]:6000: read: connection reset by peer
DEBU[0037] Trying to push localhost:6000/hello-world to http://localhost:6000 v2
DEBU[0037] Error getting v2 registry: Get http://localhost:6000/v2/: read tcp [::1]:33562->[::1]:6000: read: connection reset by peer
DEBU[0037] Trying to push localhost:6000/hello-world to https://localhost:6000 v1
DEBU[0037] attempting v2 ping for registry endpoint https://localhost:6000/v2/
DEBU[0037] attempting v1 ping for registry endpoint https://localhost:6000/v1/
DEBU[0037] Trying to push localhost:6000/hello-world to http://localhost:6000 v1
DEBU[0037] Image list: [0xc820aa3840 0xc820704500]
DEBU[0037] Tags by image: map[sha256:690ed74de00f99a7d00a98a5ad855ac4febd66412be132438f9b8dbd300a937d:[latest]]
DEBU[0037] Pushing ID: b652ec3a27e758f30de4742156b5d096bb19c82f2dc836e96e430323ba166ffe with Tag:
DEBU[0037] Pushing ID: 690ed74de00f99a7d00a98a5ad855ac4febd66412be132438f9b8dbd300a937d with Tag: latest
DEBU[0037] [registry] PUT http://localhost:6000/v1/repositories/hello-world/
DEBU[0037] Image list pushed to index:
[{"id":"b652ec3a27e758f30de4742156b5d096bb19c82f2dc836e96e430323ba166ffe"},{"id":"690ed74de00f99a7d00a98a5ad855ac4febd66412be132438f9b8dbd300a937d","Tag":"latest"}]
DEBU[0037] Not continuing with error: Put http://localhost:6000/v1/repositories/hello-world/: EOF

注册表日志最后显示发生了错误,但从日志的其余部分我实际上无法辨别出错误是什么。我甚至将日志拆分为 stdout 和 stderr,但 stderr 中没有任何内容。

此外,我已确认注册表正在监听 ipv4。运行nc -l -4 6000返回Address already in use。至少,我认为我已经确认了这一点。ipv4 地址仍然不会显示netstat

更新6

使用 明确指定了 ipv4 端口docker run -d -p 127.0.0.1:8000:8000,此端口在 netstat 中显示为正在监听。仍然出现相同的错误。不过 Docker 日志略有不同:

time="2016-04-07T15:19:31Z" level=warning msg="No HTTP secret provided - generated random secret. This may cause problems with uploads if multiple registries are behind a load-balancer. To provide a shared secret, fill in http.secret in the configuration file or set the REGISTRY_HTTP_SECRET environment variable." go.version=go1.5.3 instance.id=6391e3dc-6644-4a45-8e8b-a08c8ff798a6 version=v2.3.1
time="2016-04-07T15:19:31Z" level=info msg="redis not configured" go.version=go1.5.3 instance.id=6391e3dc-6644-4a45-8e8b-a08c8ff798a6 version=v2.3.1
time="2016-04-07T15:19:31Z" level=info msg="Starting upload purge in 1m0s" go.version=go1.5.3 instance.id=6391e3dc-6644-4a45-8e8b-a08c8ff798a6 version=v2.3.1
time="2016-04-07T15:19:31Z" level=info msg="using inmemory blob descriptor cache" go.version=go1.5.3 instance.id=6391e3dc-6644-4a45-8e8b-a08c8ff798a6 version=v2.3.1
time="2016-04-07T15:19:31Z" level=info msg="listening on [::]:5000" go.version=go1.5.3 instance.id=6391e3dc-6644-4a45-8e8b-a08c8ff798a6 version=v2.3.1
time="2016-04-07T15:20:31Z" level=info msg="PurgeUploads starting: olderThan=2016-03-31 15:20:31.061864096 +0000 UTC, actuallyDelete=true"
time="2016-04-07T15:20:31Z" level=info msg="Purge uploads finished.  Num deleted=0, num errors=1"
time="2016-04-07T15:20:31Z" level=info msg="Starting upload purge in 24h0m0s" go.version=go1.5.3 instance.id=6391e3dc-6644-4a45-8e8b-a08c8ff798a6 version=v2.3.1

“redis 未配置”消息是唯一看起来可能存在问题的消息。我会调查一下。非常非常感激任何额外的见解。

答案1

我写这篇文章是因为我花了几个小时才最终解决这个问题。

我的情况:我在 Fedora 25 上运行 docker 版本 17,并尝试使用自定义配置文件运行注册表,并收到与上述相同的对等重置消息。这种情况似乎是由于不安全的 HTTP 连接被重置而发生的,因此我发现有人告诉我DOCKER_OPTS="--insecure-registry localhost:6000 127.0.0.1:6000"/etc/sysconfig/dockerand/etc/default/docker文件中添加选项,然后重新启动 docker 服务。然而,这并没有解决问题(这里是有关该内容的官方文档)。

最终成功的是使用 docker compose 镜像运行注册表。我按照digitalocean 指南,它基本上指导您使用 docker-compose 设置注册表,然后使用 nginx 设置 SSL,如果在本地服务器上完成,这就可以了。

然而,事实证明我需要做的只是第 2 步,即按照docker-compose.yml给定的方式进行设置并启动注册表,瞧!推送现在可以正常工作了。

答案2

解决了问题:

必须使用 运行docker run -d -p 127.0.0.1:6000:5000。不使用 localhost 确保使用 ipv4(我很确定它在其他情况下被使用,但至少现在它显示在 netstat 中)并且容器在其端口 5000 上监听,所以它在其他情况下不起作用。

相关内容