slonopotamus / stevedore

🚢 Docker distribution for Windows Containers that Just Works
Apache License 2.0
305 stars 12 forks source link

Can't connect to a container using machine private IP or host.docker.internal #43

Closed rho-cassiopeiae closed 1 year ago

rho-cassiopeiae commented 2 years ago

Version

0.6.0

What steps are needed to reproduce the behavior?

1) Start a container with a port exposed. 2) Connect to it using "localhost" – works. 3) Connect using "host.docker.internal" or host machine private IP – doesn't work. Connection refused.

What you expected?

Connecting successfully.

What happened?

Connection refused.

Also, may be related or not: after installing Stevedore, Docker Desktop no longer has bridge network plugin installed, so it fails to create any networks. I don't run Stevedore and Docker Desktop at the same time. After uninstalling Stevedore, the plugin magically reappears and DD starts working properly again.

Additional context

No response

slonopotamus commented 2 years ago

First, WRT host.docker.internal: I believe it has a different purpose. It is used to connect from container to host. While Stevedore doesn't automagically write /etc/hosts entry for it, you can use --add-host=host.docker.internal:host-gateway to add it. See https://github.com/moby/moby/pull/40007, this is a standard Docker feature.

As for connecting to container using host IP - I need to do some investigation, no comments here yet.

rho-cassiopeiae commented 2 years ago

yeah, I know. I use host.docker.internal in my connection strings to postgres, elastic, etc., because I often launch my app as a container in the same network, but sometimes I launch it outside of docker. When I launch it alongside other containers I should use service names instead of IP addresses, and when I launch it as a standalone app I should use localhost. But I don't like having multiple config files for local dev or change values all the time, so I use host.docker.internal instead. It works for both cases, because it's just an alias for private IP.

And while Stevedore doesn't write to hosts, DD does, so I already have host.docker.internal resolving to the host's private IP. When it fails to connect there is an error saying that connection to my private IP (not host.docker.internal) refused. So it resolves just fine.

joeri-jansen commented 2 years ago

I can confirm the issue that @rho-cassiopeiae reported. With Docker Desktop, a port binding resulted in these netstat lines on the host: 0.0.0.0:8080

With Stevedore, the result is: 127.0.0.1:8080

Binding the port with -p 0.0.0.0:8080:8080 results in only a single netstat result, using Stevedore: 127.0.0.1:8080

joeri-jansen commented 2 years ago

Perhaps this is related to how WSL works? It does not expose the ports on your LAN adapter by default, however, you can make explicit mappings: https://docs.microsoft.com/en-us/windows/wsl/networking#accessing-a-wsl-2-distribution-from-your-local-area-network-lan

slonopotamus commented 1 year ago

Stevedore is no longer providing support for Linux containers. See why. I recommend switching to Rancher Desktop, Container Desktop or Colima.