What's the difference between `ports` and `expose` in Compose?
⚡
Quick Answer
ports publishes a container port to the host (host:container); expose only documents/opens a port to other containers, not the host.
Detailed Answer
ports: '8080:80' maps host 8080 to container 80, reachable from outside. expose: '80' makes the port available on the Compose network but not the host. For service-to-service traffic you need neither if they share a network — the container port is already reachable by service name.
💡
Interview Tip
Internal services usually need neither — call that out.
docker-composeportsexpose