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

jac*_*ise 5 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 localhost、、netstat -ntlp和之后iptables -t nat -nxvL,我仍然没有看到任何迹象表明任何东西正在监听127.0.0.1:6000,这是我的端口应该分配给registry(它只是作为容器运行)。相反,它似乎正在监听 :::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
Run Code Online (Sandbox Code Playgroud)

更新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
Run Code Online (Sandbox Code Playgroud)

当我尝试将映像推送到注册表时,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
Run Code Online (Sandbox Code Playgroud)

注册表日志以发生错误结束,但从日志的其余部分我实际上无法辨别该错误是什么。我什至将日志拆分为 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
Run Code Online (Sandbox Code Playgroud)

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

jac*_*ise 1

解决了问题:

不得不跑docker run -d -p 127.0.0.1:6000:5000。不使用 localhost 确保使用了 ipv4(我很确定它以其他方式使用,但至少现在它显示在 netstat 中)并且容器侦听其端口 5000,因此它无法正常工作。