I have two containers running on a docker bridge network (this can be the default docker0
, or a user-defined bridge). If I publish ports from one container, the other container cannot access those published ports via the host IP address.
Example:
$ docker run --detach -p 80:80 nginx
$ docker run --rm -it centos \
/bin/bash -c "yum install -y wget && wget http://${HOST_IP}"
...
Connecting to ${HOST_IP}:80... failed: No route to host.
In the above example, the nginx server can be accessed from the host and other servers on the network (or internet). However, the centos docker container, which has full network access, is unable to connect to port 80 on the host. All ports on the host can be accessed without issue, as long as it is not on a docker network bridge.
I have found completely disabling firewalls (firewalld and iptables) and restarting the docker service allows access, so I am reasonably certain this is a firewall issue. I found this docker libnetwork PR, but it hasn't seen any activity in 6 months.
Am I missing something fundamental about docker here? Shouldn't two containers on the same bridge network be able to communicate over a publish port? I should add that if I try to access the nginx port directly using the internal private network IP (172.X.X.X) from inside the centos container then it works. It is only when connecting out to the published host port.
I have found the above happens with both the latest centos (7.4.1708) and fedora (28) images.