Docker containers aren't just isolated processes; they have their own virtual network interfaces. Understanding how they connect to each other and the host is vital for any developer.
1. Bridge Mode (Default)
Docker creates a virtual bridge (usually docker0). Each container gets its own IP on this bridge. To reach them from the outside, you must map ports using -p 80:80.
2. Host Mode
The container shares the host's actual network stack. If your app listens on port 80, it's directly reachable on the host's IP. This is faster but less isolated.
3. None Mode
The container has no network access at all. Use this for high-security tasks like processing sensitive data that should never touch the internet.
4. Overlay Networks
Used in Docker Swarm or Kubernetes to connect containers across different physical servers.