Cannot access network port on host using bridge network

Expected behavior

Docker containers should be able to connect to network ports on the Mac OS X host using the bridge network.

On the Mac OS X host:
python -m SimpleHTTPServer 9977

In a Docker container:

➜  ~ ip route show 0.0.0.0/0
default via 172.18.0.1 dev eth0
➜  ~ curl 172.18.0.1:9977

(Expected: An HTTP response with a directory listing should be printed.)

Actual behavior

On the Mac OS X host:
python -m SimpleHTTPServer 9977

In a Docker container:

➜  ~ ip route show 0.0.0.0/0
default via 172.18.0.1 dev eth0
➜  ~ curl 172.18.0.1:9977
curl: (7) Failed to connect to 172.18.0.1 port 9977: Connection refusedd

Information

This works fine for me in Docker Toolbox on both Mac and Windows.

172.18.0.1 matches the IP of the gateway in the bridge network that my container is connected to.

These threads may be related:

$ pinata diagnose -u
OS X: version 10.11.5 (build: 15F34)
Docker.app: version v1.11.1-beta13.1
Running diagnostic tests:
[OK]      Moby booted
[OK]      driver.amd64-linux
[OK]      vmnetd
[OK]      osxfs
[OK]      db
[OK]      slirp
[OK]      menubar
[OK]      environment
[OK]      Docker
[OK]      VT-x
Docker logs are being collected into /tmp/20160605-004745.tar.gz
Most specific failure is: No error was detected
Your unique id is: C4D010FD-F5D1-429F-A865-161FE7C3C418
Please quote this in all correspondence.

I had the same on ubuntu 16.04/fedora 21, which was caused by the firewall settings on the host. I had to add:

iptables -I INPUT 3 -i <name-of-my-docker-network> -j ACCEPT

The docker container runs in the bridge network .

1 Like