How to see the logs of a docker container
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Viewing Docker container logs is essential for debugging startup failures, runtime errors, and health-check issues. The primary command is docker logs, but effective troubleshooting often requires timestamps, streaming, tail limits, and awareness of logging drivers. If a container appears silent, output may be redirected or logging configuration may route logs elsewhere. A structured logging workflow makes incident diagnosis faster.
Core Sections
1. Basic log retrieval
This prints stdout/stderr collected by Docker for that container.
2. Follow logs in real time
Equivalent to tail -f, useful for watching startup and request processing.
3. Add timestamps and tail limits
Keeps output manageable while preserving event timing context.
4. Inspect recent time window
This isolates incidents without scanning full history.
5. Compose and Kubernetes contexts
With Docker Compose:
In Kubernetes, container logs are accessed with kubectl logs, not docker logs.
6. Logging driver implications
If container uses a non-default logging driver, output may not be available via docker logs.
For drivers like syslog or fluentd, check the external sink.
Validation and production readiness
A working snippet is only the first step. To make the solution dependable, validate behavior under representative inputs and operating conditions. Build a small test matrix that includes normal cases, boundary values, and malformed data so failure modes are explicit. If the topic involves time, concurrency, or networking, add at least one test that simulates delayed execution and one test that verifies timeout handling. This catches race conditions and environment-specific bugs that rarely appear in local happy-path runs.
Operational clarity matters as much as correctness. Document assumptions near the implementation: runtime version, required dependencies, expected timezone or locale rules, and platform limitations. Ambiguous assumptions are a major source of production incidents because teammates run the same logic under different defaults. Use structured logs around critical branches and external calls so debugging does not require ad hoc reproduction. Logs should include identifiers and concise context, but avoid sensitive payloads.
For recurring jobs or frequently executed code paths, add observability and guardrails. Define simple success metrics, retry boundaries, and explicit rollback or fallback behavior. Silent retries with no upper limit can hide systemic failures and increase downstream impact. Keep a lightweight pre-deploy checklist in source control so changes remain auditable and repeatable across environments.
Teams that treat these checks as part of the default implementation workflow usually spend less time on incident triage and more time shipping stable improvements.
Common Pitfalls
- Looking at wrong container ID/name after redeploys.
- Forgetting
-fand missing live error output. - Assuming logs persist forever without rotation settings.
- Ignoring logging driver configuration when logs appear empty.
- Mixing application log files and stdout logging inconsistently.
Summary
docker logs plus -f, --tail, --timestamps, and --since covers most debugging needs. Always verify container identity and logging driver when output is missing. Standardize app logging to stdout/stderr where possible, and use external log sinks for retention and search in production.
In collaborative teams, documenting this exact workflow and enforcing it with simple CI or runbook checks prevents repeated mistakes and keeps behavior consistent across development, staging, and production environments.

