NATing - Exposing containers outside of the Host

Docker Toolbox Only

In order to expose a container outside of the host, you need to setup the NATing table on the VM.  Here is an example of some mappings

Navigating to NAT table on Virtual Box

Select Network

Expand the Advanced button

Select Port Forwarding

You can now do your settings

Understanding the NAT Table

  1. Each row must have unique name.
  2. Select the protocol to monitor (TCP as default).
  3. Specify the IP address on the host to listen on.
  4. Specify the port number on the host for the corresponding IP address to listen on.
  5. For the next step, consider the following result of docker ps
  6. Docker is running on Windows Home OS, so it is Docker ToolBox.  docker machine IP is 192.168.99.100.
  7. There are two tomcat 9 instances running, one called t9s and the is called t9s-hanc.  There is a MySQL instance called mysql-hanc.
    1. t9s is exposed on the host on port 8080
    2. t9s-hanc is exposed on the host on port 8091
    3. mysql-hanc is exposed on the host on port 3307
  8. The Guest IP should be the IP of Docker-Machine
  9. The Guest Port should be the port you have exposed the container on to the host, not its internal port e.g. mysql-hanc internally runs on port 3306 but expose it on 3307, notice the port number we have specified

Important

For each host IP i.e the loopback (127.0.0.1) and it's assigned IP (if from a DNS) should be specified in the NAT Table in order to monitor traffic on that interface.