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
Connecting container to multiple bridge networks breaks port forwarding from external IPs #21741
Comments
It seems what you need is the ability to define the |
|
It now seems that it's not he I'm slightly suspicious that maybe this is due to something sticky (since I could have sworn it worked when I first tried it), but the behaviour is persisting over deleting the networks and containers and rebooting the machine. It would be great if someone could confirm the behaviour I'm seeing. |
|
Running the daemon with |
|
Having the same problem. In my case (running on CentOS 7 on AWS) |
|
I also have the same issue. I found out that it seems to be an intermittent problem as restarting the compose project many times finally made the port forwarding working. |
|
Same issue for me too. Workaround com.docker.network.internal doesn't solve with my compose version? Any suggestion? Proposal for next compose release in key "ports": specify ports HOST_PORT:CONTAINER_NETWORK:CONTAINER_PORT too. docker info docker-compose version 1.7.0rc1, build 1ad8866 docker-compose.yml file: version: '2' services: networks: Test1 (when it is broken): Test2 (when it works) |
|
As @railnet pointed out I have the same issue (docker/compose#3318). |
|
It seems to me an active discussion on similar symptoms is active here too: May you confirm I'm right? |
|
I just did a test by following the approach here below reported, but it doesn't solve. As reported here: Then, I have configured --ip=172.18.0.1 , I restarted the Docker daemon, but the iptables in the host are not coherent. Refer to my previous post for more details. |
|
@railnet I've not actually tried it, but my understanding of |
|
Just tried with docker version 1.11.0 and now it works. Will be doing more testing to make sure it's not transient. |
|
Hi @choobs-dev unfortunately I just verified the issue is still present with the following versions: Server: docker-compose version 1.7.0, build 0d7bf73 |
|
I am not sure about the specific issue you are hitting and a work-around in the context of compose. When a container connects to multiple networks providing external connectivity (ex. more than one bridge network), the container's default gateway is dynamically chosen among the ones provided by the networks based on a certain rule. The programming of the port-mapping has to be coherent with the container's chosen default gateway, therefore it needs to change if the default gateway changes. 1.11 finally respects this. |
|
Hi @aboch , Anyway, it is not clear to me the principle used by docker 1.11 as to choose the port mapping. Many Thanks in advance. @choobs-dev included in this post too, because we are discussing on "compose" and he opened an issue on it. |
From the container perspective, being connected to multiple networks is like a server with multiple NICs. In such case you end up with multiple default gateways in the host routing table but only one will be used, the one on top of the table. Same end result for container where libnetwork makes sure only one default gw is programmed.
libnetwork chooses the default gateway for the container based on the priority associated to the network attachment point (Endpoint). Given the UI does not provide yet a way for user to set this priority, we fall-back to default logic which is choosing the first network in alphabetically order... That is why it is choosing the
Based on the current container's default gateway
I am not sure I understand this. You can configure multiple routes, but the default is the default (0.0.0.0/0). And if more default routes are specified, then only the one on top will be used. And the order is dictated by their metric, the lowest the first.
A container does never become the gateway for a network. The network has its own gateway (for bridge network is the bridge interface). When you connect a container to a network, the network driver provides libnetwork with the default gateway to be programmed for the container. In most cases, the network gateway is the one returned, unless you play with driver options and are telling the bridge driver to return a custom chosen IP.
Please try play with the network names. |
|
Hi @aboch The core of the post is obviously the sentence "we fall-back to default logic which is choosing NOw I can share that it solves for me and then the issue can be closed from my point of view. Issue solved. Have a great time |
|
@railnet The default gateway pick up logic has been in place since docker supports container connecting to multiple networks. Clearly this has not been spelled out enough, even though there are some issue opened in docker/docker and libnetwork. So the blame is on us. We must specify it in the documentation if not already present. |
|
This is my attempt at an explanation of this problem: |
It may just be a problem on my machine, but it seems that creating a container that sits on two networks is somehow interfering with port forwarding. The forwarding works when accessing 127.0.01, but not when accessing the IP address for another interface.
Output of
docker version:Output of
docker info:Additional environment details (AWS, VirtualBox, physical, etc.):
Physical machine
Steps to reproduce the issue:
docker-compose.ymlfile with the following contentIn actual use, there would be other services connect to the
backnetwork but not thefrontnetwork, but they're not necessary to demonstrate the bug.2. With docker-compose 1.6.2, run
docker-compose up.3. From the host, run
curl http://localhost:8080.4. From the host, run
curl http://IPADDRESS:8080, where IPADDRESS is an IP address of a non-local interface on the machine.Describe the results you received:
Step 3 spits out an HTML page from nginx. Step 4 outputs nothing and eventually times out.
Describe the results you expected:
Step 4 should return the same HTML page as step 3.
Additional information you deem important (e.g. issue happens only occasionally):
I'm not running any other firewall software on this machine. If I remove the config line putting the service on the
backnetwork, then the problem disappears. Similarly, if I rundocker network disconnectto disconnect the container from thebacknetwork, the problem disappears, and reconnecting it makes the problem come back.Output of iptables -vnL:
Output of iptables -t nat -vnL
The text was updated successfully, but these errors were encountered: