docker 推送到注册表不起作用

docker push to registry does not work

我在尝试推送到我之前创建的注册表时遇到问题。这是我遵循的步骤。

docker run -d -p 5001:5002 --restart=always --name new_registry registry:2

docker build -t test-app .

docker run -p 50100:8080 -d --name app test-app
docker tag test-app localhost:5001/test:latest
docker push localhost:5001/test:latest

=========================================== ====

 ✘  ~/G/S/d/a/App   master   docker push localhost:5001/test:latest
The push refers to a repository [localhost:5001/test] (len: 1)
Sending image list
Put http://localhost:5001/v1/repositories/test/: net/http: transport closed before response was received

下面是 docker images 命令的输出:

  ~/G/S/d/a/App   master   docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
test-app              latest              78f9362f7cd5        51 minutes ago      547.8 MB
localhost:5001/test   latest              78f9362f7cd5        51 minutes ago      547.8 MB
registry              2                   5d165b8e4b20        3 weeks ago         220.1 MB

下面有更多详细信息:

 ~/G/S/d/a/patterns_and_tools  docker-machine env default
set -x DOCKER_TLS_VERIFY "1";
set -x DOCKER_HOST "tcp://192.168.yyy.xxx:2376";
set -x DOCKER_CERT_PATH "/Users/zack/.docker/machine/machines/default";
set -x DOCKER_MACHINE_NAME "default";
# Run this command to configure your shell:
# eval (docker-machine env default)
 ~/G/S/d/a/patterns_and_tools 

我检查了 VM 中的网络设置。他们如下:

名称:docker设置 协议:TCP 主机 IP: 主机端口:50100 访客IP: 来宾端口:50100

标签 boot2docker (even though it has been obsoleted by docker machine) 表示您不是直接在 Linux 上,而是在 Windows 或 Mac 上,使用 Linux 虚拟机。

您在 issue 523 of docker/distribution(新注册服务器)

中报告了类似的错误消息

When you bind to localhost inside the container, the service won't be available outside the container, even though you are specifying the port mapping.
When the docker daemon goes to connect, it cannot connect to the port since the service is not bound to the "external" interface of the container.

这意味着您需要设置

docker push $(docker-machine ip new_registry):5001/test:latest

5000:5000 works but 5001:5002 does not work when creating registry.

可能虚拟机已经被设置为转发端口 5000,而不是 5001(类似于 this picture)。

这意味着 registry image exposes port 5000:您可以将其映射到主机端口 5000 或 5001 或您想要的任何端口:但它必须是您映射的端口 5000 :

docker run -d -p 5001:5000 --restart=always --name new_registry registry:2
                      ^^^^