9.4.3 Compose Logs
A focused guide to Compose Logs, connecting core concepts with practical Docker and container operations.
docker compose logs retrieves and displays log output from one or more of an application's services, providing a unified way to inspect what's happening across a multi-container application without needing to check each container's logs individually through separate commands.
Viewing Logs From Every Service
Without specifying a particular service, logs displays output from every service in the application together.
docker compose logs
api_1 | Server listening on port 8080
db_1 | database system is ready to accept connections
Each line is prefixed with the originating service's name, making the combined output still distinguishable by source.
Viewing Logs From a Specific Service
Naming a particular service limits output to just that one.
docker compose logs api
Following Logs Live
The -f flag streams new log output continuously, rather than simply displaying what's already been logged and then stopping.
docker compose logs -f api
This behaves similarly to tail -f, continuing to display new log lines as they're produced until interrupted.
Limiting Output to Recent Log History
The --tail flag limits output to a specific number of the most recent lines, useful for avoiding an overwhelming amount of historical output for a service that's been running and logging for a long time.
docker compose logs --tail=50 api
Including Timestamps in Log Output
The -t flag adds a timestamp to each log line, useful for correlating log entries with when they actually occurred.
docker compose logs -t api
Why Compose Logs Matters
This unified log viewing command is essential for understanding and troubleshooting a multi-container application's behavior, providing convenient access to exactly the log output needed without requiring separate, manually issued commands against each individual container.