-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't connect to docker container's exposed port with network's gateway ip from other container #5588
Comments
+1 seeing the same issue |
Thanks for your report. For maximum compatibility/portability between systems I recommend
The networking implementation on macOS is different to native Linux as there are two kernels with separate network stacks. On Linux |
The issue we are having is within a Python library (https://github.com/testcontainers/testcontainers-python) that uses the approach I've described (network gateway ip + port) to communicate between containers it starts, so we can't change that. For now we were able to fix this, by explicitly binding the ports we want to expose instead letting docker do it. But if you're saying using the internal DNS and IP is recommended, maybe that is a ticket to open on the repository of the library we are using. |
So is this a 'Won't Fix', then? This used to work fine on Docker for Mac. I support Dockerized utilities in both Linux and Mac environments and use this behavior often. I also tried hitting the listening container by it's IP when troubleshooting and that didn't work. when did this behavior change? I didn't see any notes about it in the changelogs. I'm also unable to get back to a working state by uninstalling and installing an older version. I'm suspicious this is due to a recent networking components update, and I noticed the uninstall does not ask for privileged access like the install does. Does a uninstall also uninstall the networking components? |
I see the same behaviour with https://github.com/testcontainers/testcontainers-go |
Issues go stale after 90 days of inactivity. Prevent issues from auto-closing with an If this issue is safe to close now please do so. Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. |
We're looking into something that looks awfully similar with testcontainers-java, whereby GATEWAY_IP:PORT connections fail in Docker for Mac & Windows from one container to another. testcontainers/testcontainers-java#4395 We're not quite sure where our investigations will lead us yet, but we'll update here if we find something useful. |
/remove-lifecycle stale ^ on the basis that this used to work just fine and has become relied upon, so removal without warning is not without impacts. |
Based on some initial tinkering there's something weird going on here, but it gives us some ideas for a workaround that could be applied to testcontainers-java and probably other similar libs:
I was always under the impression that Taking @illesguy's repro script above and simply sticking a @djs55, for various use cases (particularly CI environments with 'docker wormhole' arrangements) the Could you perhaps give us a steer on:
Thank you in advance. |
@rnorth sorry for the delay in replying. The observation about |
I've done a bit of investigating and I believe this problem is due to the fix for docker/for-win#10008 . On Mac and Windows There was a bug in this bugfix, in the test for "is the user requesting a random port". The code checks for the port being "", but not the port being "0". So the reason that Considering the possibility of making
I could probably fix (1) by binding internally on It is possible to bypass the Docker API proxy which is rewriting the port number:
I don't know how convenient this would be to change. It's a bit of an internal detail of Docker Desktop. So in summary:
|
❤️ |
@djs55 thank you so much for the detailed analysis and explanation! I really appreciate you spending time looking into this. We'll have some internal talks to discuss what we do at our end, but my immediate thoughts are (in no particular order):
I think I'd strongly echo @gesellix's ❤️ reaction: this ought to help us implement the 'accidental workaround' with much more confidence. Having the behaviour be covered by a test is a great idea - thanks.
I learned something new today 😄. Slightly longer term, this wouldn't be a trivial change for us, but might be something we could use from the Testcontainers side if essential. We already have to cater for other differences when we're running inside a container, so extending this might be practical if we can do it safely. My only concern would be that we'd be even deeper into coupling to Docker Desktop internals, so we have to consider that. We'll keep this ticket updated with plans from the Testcontainers side. Thanks again. |
Issues go stale after 90 days of inactivity. Prevent issues from auto-closing with an If this issue is safe to close now please do so. Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. |
Closed issues are locked after 30 days of inactivity. If you have found a problem that seems similar to this, please open a new issue. Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. |
Expected behavior
When creating a docker container with an exposed port (not binding it), be able to reach the application running on it from another container in the same network using the network's gateway ip and the port the container was assigned on the host.
HostPort
in the docker container'sHostConfig
,PortBindings
should be empty. This is the behaviour on Ubuntu.Actual behavior
When creating a docker container with an exposed port (not binding it), can reach the container from the host with localhost and the newly assigned port but not from another container with their network's gateway ip and the newly assigned port.
HostPort
in the docker container'sHostConfig,
PortBindings` is set to "0". This is the behaviour on Mac.Information
The problem is reproducible. Not sure if it's new, we just noticed it and the not sure whether it came with an update. Added steps to reproduce below. When the run a container and use the
-p <port>
option to map the container's port to a randomly assigned one on the host machine, we noticed that HostPort under HostConfig and PortBindings in the container's config is set to "0", on Ubuntu it is an empty string. If we were to specify the port we want to bind to it works fine-p <host_port>:<container_port>
. In this case theHostPort
underHostConfig
/PortBindings
would be thehost_port
we specified on both Mac and Ubuntu. We suspect this is causing the issue.macOS version: 10.15.6
Docker Desktop Version: 3.3.1
Docker version: 20.10.5
Ubuntu host tested on: 18.04.5
Docker version: 20.10.6
Reproduce
The following script would reproduce the issue, it would fail on Mac and succeed on Ubuntu:
The text was updated successfully, but these errors were encountered: