I want to push an image to a private remote registry via SSH, but I am getting an error when running the following in macOS:
% docker push localhost:5000/my_image:1
...
Get "http://localhost:5000/v2/": dial tcp [::1]:5000: connect: connection refused
Interestingly, in the very same terminal:
% curl http://localhost:5000/v2/
{}
which proves that the SSH connection is working.
This registry does not have any remote registry URL. It is only accessible via SSH.
As mentioned, once the SSH connection is established http://localhost:5000/v2/
is accessible (from both a browser and with the command curl http://localhost:5000/v2/
).
Running docker push ...
from a Linux machine also works fine.
Considering all this, it looks like the problem is some sort of compatibility issue between the SHH tunnel and the commands run via docker ...
in macOS.
This page seems to have a plausible explanation:
You can now run docker push like this:
... $ docker push localhost:5000/really_cool_image:3.1.2
Doing this on macOS
If you try to do the above with docker for mac, you’ll probably find yourself with an error like this:
The push refers to a repository [localhost:5000/really_cool_image] Put http://localhost:5000/v1/repositories/really_cool_image/: dial tcp 127.0.0.1:5000: getsockopt: connection refused
What’s happening here is that docker can’t access the ssh tunnel you setup on the mac,
because of the way Docker works on macOS. Essentially, your mac and
docker have two different 127.0.0.1 addresses.
Unfortunately, the solution proposed in that page does not seem to work anymore as of 2024 (there are no tty files in the latest versions of Docker).
Any idea of how to make docker push ...
work in macOS with an SSH tunnel?
Other things I already tried but did not help
- Using
127.0.0.1
instead oflocalhost
to force using IPv4 instead of IPv6. - Try to
pull
instead ofpush
, to check if it was a write only problem (it is not,pull
returns the same connection error). - Other similar questions like this one or this one are either too old, do not apply to macOS, or are not with an SSH tunnel.