Search code examples
dockerdocker-for-windows

docker windows exposed ports cannot be accessed from outside the host


I have Docker installed on a Windows 10 host (running Linux container):

Client:
 Version:      17.03.1-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Tue Mar 28 00:40:02 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.03.1-ce
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Fri Mar 24 00:00:50 2017
 OS/Arch:      linux/amd64
 Experimental: true

I ran a simple command like this:

docker run -d -p 80:80 --name webserver nginx

From my host, I can access it with http://localhost, http://127.0.0.1, http://192.168.1.151 (eth0), http://172.24.1.16 (eth1), etc.

However, from outside the host, on both 192.168.1.0/24 and 172.24.1.0/24 sub-nets, accessing the web server returns in time-out errors.


Solution

  • the linux machine inside of docker is already configured to expose ports.

    99 times out of 100, it's Windows Firewall. try turning it off entirely.

    if that doesn't work, possibly add --cap-add=NET_BIND_SERVICE to your docker run command (via https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities).