docker logs prints the stdout and stderr a container has produced. In CI it is the first stop when a service container fails to start or a test cannot connect; dumping logs in a failure step turns an opaque error into a readable one.
Common flags
-f, --follow - stream new log output (avoid in CI unless backgrounded)
--tail - show the last N lines, e.g. --tail 100
--since - show logs after a timestamp or relative time, e.g. 5m
-t, --timestamps - prefix each line with a timestamp
Add a failure step that runs docker logs --tail 200 for each service container so a flaky integration test leaves actionable output. Do not use -f in a normal step (it blocks forever); if you must follow, background it or bound it with timeout.
Key takeaways
--tail and --since bound output to the relevant recent window.
Dump logs in an on-failure step to debug service-container errors.
Avoid -f in foreground CI steps; it never returns.
Frequently asked questions
docker logs Command Reference?
docker logs prints the stdout and stderr a container has produced. In CI it is the first stop when a service container fails to start or a test cannot connect; dumping logs in a failure step turns an opaque error into a readable one.
In CI?
Add a failure step that runs docker logs --tail 200 for each service container so a flaky integration test leaves actionable output. Do not use -f in a normal step (it blocks forever); if you must follow, background it or bound it with timeout.