How does container networking work in Docker, and how do containers talk to each other?
What they are really testing: Whether you understand the default bridge, publishing ports, and that user-defined networks give name-based discovery. A frequent source of "it works locally but containers cannot reach each other".
A real interview question
How does container networking work in Docker, and how do containers talk to each other?
What most people say
drag me
“Containers get an IP address and you map ports with -p to access them.”
It covers port publishing but misses container-to-container discovery: on the default bridge they cannot resolve each other by name, which is exactly why multi-container setups fail until you use a user-defined network or Compose.
The follow-ups they ask next
Two containers cannot reach each other by name. What is the fix?
Put them on the same user-defined bridge network (or use Compose), which enables Docker built-in DNS so they resolve by container name. The default bridge does not provide name resolution.
What is the difference between EXPOSE and -p?
EXPOSE is metadata documenting the port; -p (publish) actually maps a host port to the container port so it is reachable from outside. EXPOSE alone makes nothing reachable.
What the interviewer is listening for
- Knows default bridge + outbound-only until published
- Knows -p publishes, EXPOSE documents
- Knows user-defined networks give name DNS
What sinks the answer
- Only knows -p
- Thinks default bridge gives name resolution
- Confuses EXPOSE with publishing
If you genuinely do not know
Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.
“A container [joins a bridge network with an internal IP, outbound works but it is not reachable until you publish a port with -p]. [EXPOSE only documents]. For container-to-container by name, [use a user-defined network (or Compose) for Docker built-in DNS, the default bridge has none]. Other modes: [host, none, overlay].”
Keep going with docker
Foundation
What is a container, and how is it different from a virtual machine?
Foundation
What is the difference between a Docker image and a container?
Foundation
What is a Dockerfile, and what do the main instructions do?
Junior
How does the Docker build cache work, and how do you order a Dockerfile to use it well?
Junior
What is the difference between CMD and ENTRYPOINT, and what is the exec versus shell form?
Junior
How do you persist data in Docker? Explain volumes versus bind mounts.
Knowing the answer is not the same as recalling it under pressure
Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.
Start free