docker logs Command Reference
Fetch the logs of a container.
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--until- show logs before a timestamp
Example
shell
docker logs --tail 200 --timestamps app-db
docker logs --since 2m app-webIn 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.
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.
Related guides
docker ps Command ReferenceReference for docker ps in CI: list running or all containers with -a, -q, --filter, and --format to inspect…
docker inspect Command ReferenceReference for docker inspect in CI: print low-level JSON for containers, images, volumes, and networks, and e…
docker compose logs Command ReferenceReference for docker compose logs in CI: view aggregated service logs with --tail, --no-color, and --timestam…