Docker Compose default networking
Compose networking internals.
Compose creates one default user-defined bridge network for the project; all services join it and reach each other by service name via embedded DNS, isolated from other projects.
WHAT THIS TESTS It checks deeper knowledge of what Compose sets up automatically and why service-name resolution works without any explicit network or links.
A GOOD ANSWER COVERS On docker compose up, Compose creates one default network for the project, a user-defined bridge typically named <project>_default, and connects every service to it. The crucial detail is that user-defined bridge networks, unlike Docker's legacy default bridge, include an embedded DNS server, so containers can resolve each other by service name automatically. Each service is also reachable by name, and Compose scopes the network per project so two unrelated projects do not collide or see each other. You only declare networks explicitly when you need segmentation, such as separating a frontend network from a backend network, or connecting to an external network. The deprecated links directive is unnecessary because DNS-based discovery handles it.
COMMON WRONG ANSWERS Saying services share the default bridge network, which lacks automatic DNS resolution. Believing you must use links. Assuming all Compose projects share one flat network. Confusing service name resolution with host networking.
LIKELY FOLLOW-UPS How does a user-defined bridge differ from the default bridge? When would you define multiple networks? How does network scoping isolate projects?
ONE CONCRETE EXAMPLE A project with web, api, and db services and no networks block: Compose creates myproject_default and attaches all three. api connects to db:5432 and web calls api:8000, all resolved by the embedded DNS on that bridge, while a separate project's containers on their own default network remain invisible.
Interview question
Why can Compose services resolve each other by name on the default network but containers on Docker's legacy default bridge cannot?
- a.Compose creates a user-defined bridge, which includes embedded DNS, unlike the legacy default bridgeCorrect
- b.Compose uses host networking by default
- c.Compose disables DNS to force using IP addresses
- d.The legacy bridge resolves names but only across different hosts
Why? this is the answer
Compose's per-project network is a user-defined bridge with embedded DNS enabling name resolution, whereas Docker's legacy default bridge lacks automatic DNS; Compose neither disables DNS nor uses host networking by default.
Just read this? Test yourself on what you have been reading.
Read the original → docs.docker.com
- #docker-compose
- #networking
- #bridge
- #dns
- #isolation
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles