Docker Expose Ports

Docker for Windows runs in a virtual machine and therefore it needs a little bit more settings to expose the ports of the docker.

Set up connection to container

Bridge mode

Expose ports from 172.17.0.X (container IP) to 192.168.99.X (Virtual Box IP)

  • Either use EXPOSE in Dockerfile or use -p in docker run command.
  • Use docker-machine ls to get the Virtual Box IP. (Probably for Docker Toolbox only)

Forward connection from other interfaces to Virtual Box Interface

  • Add:
    1
    netsh interface portproxy add v4tov4 listenport=445 listenaddress=0.0.0.0 connectport=32791 connectaddress=192.168.99.100
  • Delete:
    1
    netsh interface portproxy delete v4tov4 listenport=445 listenaddress=0.0.0.0
  • List:
    1
    netsh interface portproxy show v4tov4

or

Host mode

Simply listen on the Virtual Box IP, as the docker container should be on this interface

Forward connection from other interfaces to Virtual Box Interface

Similar as above, but note that the connectport should be the direct port that is listened by the container.

Miscs

Add a route using netsh:

1
netsh interface ipv4 add route 192.168.1.100/32 metric=10 12 136.0.98.19