How do services in a Compose file communicate?
⚡
Quick Answer
They join a default network and reach each other by service name as the hostname.
Detailed Answer
Compose creates a network and attaches each service; a service named db is reachable at hostname db on its container port. You don't publish ports for internal traffic — only expose ports to the host with ports: when you need external access. depends_on controls start order (not readiness).
Code Example
services:
web:
build: .
depends_on: [db]
db:
image: postgres:16💡
Interview Tip
Clarify depends_on orders startup but doesn't wait for readiness.
docker-composenetworkingdns