Docker Networking

A Docker container has its own networking namespace, isolated from the machine it is running on. Your computer has its own networking namespace, which is a shared set of IP routing tables. To view your networking namespace,


Likely you will see at least two interfaces

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet  netmask

The loopback interface, lo, enables communication within your computer. Notice the loopback interface has an IP address of - if you serve a web app at this IP address, you can access that app by entering the IP address into your browser. lo is an internal IP address - only your computer can communicate on this interface. This computer uses the IP address to communicate externally.

Docker namespaces

Docker containers have their own networking namespace. To view the networking namespace in a Docker container, use the following command and replace 123456 with your container ID

docker exec 123456 ifconfig

To run a Docker container on the host network, use the --net host flag

docker run --net host myapp

External Resources