What are the bridge, host and none network modes in Docker?
bridge (default) gives a container its own network and IP behind a virtual switch, host shares the host's network stack with no isolation, and none disables networking except loopback.
Explain it simply
Picture a college hostel. Bridge mode is each student in their own room on a shared corridor, reaching the outside through the main gate. Host mode is the student sleeping in the warden's room, using the warden's phone line. None is a room with no door at all.
With bridge, Docker creates a virtual switch on the host. Each container gets a private IP, and -p rules forward host ports to it. With host (--network host), the container uses the host's IP and ports directly, so -p is ignored and port clashes are possible. It is faster but not isolated, and works as expected on Linux (Docker Desktop behaves differently). With none, the container has only a loopback interface, useful for offline batch jobs and tight isolation.
For several containers talking to each other, create your own bridge network.
Example
docker run -d --network bridge nginx # default
docker run -d --network host nginx # uses host port 80 directly
docker run -d --network none alpine sleep 600
docker network lsWhat to say in the interview
"bridge is the default private network with port mapping, host removes network isolation by sharing the host stack, and none leaves only loopback. I use user-defined bridge networks for multi-container apps."
Common mistakes
- Combining --network host with -p and expecting port mapping to work.