Debugging with Compose: Logs and Container Exec
When something goes wrong in your stack, you need clear visibility into what each container is doing.
1. Viewing Service Logs
To view output logs from all running services simultaneously:
# Print logs from all services
docker compose logsStreaming Logs in Real Time
To follow logs continuously as new lines are written (like tail -f):
# Stream logs from all services
docker compose logs -f
# Stream logs from a single service only
docker compose logs -f api2. Checking Service Status
To see the current state of all services in your stack:
# Display container names, status, and port information
docker compose ps3. Running Commands Inside Containers
To open an interactive terminal session inside a running service container:
# Open a bash shell inside the 'api' service container
docker compose exec api bash
# Run a single command inside the 'database' service container
docker compose exec database psql -U postgresThis is useful for:
- Inspecting database table contents.
- Running migration scripts manually.
- Debugging file system contents inside a running container.
Published on Last updated: