First, let me explain my setup: I have Ubuntu 14.04 installed in a virtual machine on a macOS. In the VirtualBox settings, I created a NAT network and I gave Ubuntu this IP address: 192.168.56.101. Inside Ubuntu, I have Docker installed. I created a Docker container that runs a python server which listens on 127.0.0.1:5001. The Docker file exposes the port 5001 so that it is reachable from the outside. I also added the following iptable rules:
IPT=/bin/iptables $IPT -P OUTPUT ACCEPT $IPT -P INPUT ACCEPT $IPT -P FORWARD ACCEPT $IPT -t nat -P OUTPUT ACCEPT $IPT -t nat -P PREROUTING ACCEPT $IPT -t nat -P POSTROUTING ACCEPT $IPT -t nat -A PREROUTING -p tcp -i eth1 --dport 5001 -d 192.168.56.101 -j DNAT --to 127.0.0.1:5001 Now, when I try to connect to it either from the host machine or from Ubuntu, it says connection refused. Can anyone tell me what's the issue here?