7.1.2 Service Communication
A focused guide to Service Communication, connecting core concepts with practical Docker and container operations.
Service communication is the broader practice of designing how multiple containers in a multi-container application reach each other reliably — typically through a shared user-defined network and name-based resolution, rather than hardcoded IP addresses — supporting a coherent, properly connected overall system.
Establishing a Shared Network for Communicating Services
Containers that need to communicate with each other are typically placed on the same user-defined network, enabling them to resolve each other by name.
docker network create app-network
docker run -d --name api --network app-network myapi:1.0
docker run -d --name db --network app-network postgres:16
The api container can reach db directly by name, without needing to know or hardcode any specific IP address.
docker exec api ping db
Configuring an Application to Use Service Names
An application's configuration should reference dependent services by their container name (or an equivalent service name in an orchestrated environment), relying on the network's name resolution rather than a fixed address.
docker run -d --name api --network app-network -e DATABASE_HOST=db myapi:1.0
Why Reliable Service Communication Requires Deliberate Network Design
Without explicit attention to which containers share a network, and how each one is configured to locate the others, a multi-container application's components may simply be unable to reach each other, despite each individual container running correctly on its own.
docker network inspect app-network --format '{{json .Containers}}'
Confirming which containers are actually attached to the expected shared network is a useful troubleshooting step when communication isn't working as expected.
Why Service Communication Matters
Deliberately designed service communication — shared networks, name-based resolution, properly configured service references — is foundational to building multi-container applications whose individual pieces actually function together as a coherent whole, rather than as isolated, disconnected components.