Search code examples
dockerboot2dockerdockerfiledocker-registrydevops

docker push to registry does not work


I am facing issues when I try to push to registry that I created earlier. Here are the steps that I followed.

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

Below is output of docker images command:

  ~/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

More Details Below:

 ~/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 

I checked the network settings in the VM . They are as below:

Name : dockersetting protocol : TCP HOST IP: HOST PORT : 50100 GuestIP : Guest Port : 50100


Solution

  • A tag boot2docker (even though it has been obsoleted by docker machine) means you are not on Linux directly, but on Windows or Mac, using a Linux VM.

    You have a similar error message reported in issue 523 of docker/distribution (the new registry server)

    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.

    That means you need to setup port forwarding, or to use the docker-machine ip new_registry ip address.

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

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

    It is possible that the VM was already set to port forward port 5000, but not 5001 (similar to this picture).

    It means the registry image exposes port 5000: you can map that on host port 5000 or 5001 or any port you want: but it has to be port 5000 that you map:

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