Docker · Containers in practice

How does Docker networking work?

MediumnetworkingbridgednsUpdated Oct 2026
Quiz this track

Short answer

Docker creates virtual networks and attaches containers to them. User-defined bridge networks provide automatic DNS by container or service name, which is how containers find each other.

The default bridge network connects containers but does not provide automatic name resolution, so containers must use IP addresses or legacy links. A user-defined bridge network provides an embedded DNS server, so a container can reach another by its name or network alias.

sh
docker network create app-net
docker run -d --name db --network app-net postgres:16
docker run --rm --network app-net alpine sh -c "getent hosts db"
On app-net, the database is reachable as db rather than by IP.

Network drivers

  • bridge: the default for standalone containers on one host
  • host: shares the host network namespace, removing port isolation
  • none: no networking, useful for isolated batch jobs
  • overlay: connects containers across multiple hosts in a cluster
  • macvlan: gives a container a MAC address on the physical network

Only containers on the same network can reach each other directly. That is a useful segmentation tool: put the database and application on an internal network and expose only the proxy to the outside.

Publishing a port with -p exposes it on the host regardless of which container network it uses. Network membership controls container-to-container access, not host exposure.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why does the default bridge not resolve container names?
  2. 2When would you use host networking?
  3. 3How do you isolate a database from the public network?
  4. 4What is an overlay network used for?

Say it in the interview

Docker creates virtual networks and attaches containers to them. I use a user-defined bridge network because it gives embedded DNS, so the app reaches the database by service name. I also use separate networks for segmentation, keeping the database off the public-facing network and exposing only the proxy. Host and overlay modes solve different problems, but both change the isolation model.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Docker mock interview and get scored feedback on depth, clarity and confidence.