Fetch and stream logs from a Docker container.
low risk
docker logs retrieves the stdout/stderr output of a container. The -f flag follows live output, --since filters by time, and --tail limits lines. For containers using json-file or local log drivers; doesn't work with syslog/journald drivers.
| Flag | Meaning |
|---|---|
-f --follow | Stream logs in real time |
--tail | Number of lines to show from end |
--since | Show logs since timestamp or duration |
--timestamps | Show timestamps |
docker logs -f --tail 100 mycontainerFollow last 100 lines of container logs · explain & risk-check →docker logs --since 30m mycontainerLogs from last 30 minutes · explain & risk-check →docker logs --timestamps mycontainer 2>&1 | grep ERRORFilter errors with timestamps · explain & risk-check →Use `docker logs --since $(date -d '1 hour ago' -u +%Y-%m-%dT%H:%M:%SZ)` to get exactly one hour of logs aligned to UTC — useful for incident correlation.
Reference text is hand-written and may be incomplete — check man docker for your version. Test destructive commands on a non-production system first.