docker-container-logs
TLDR
Print logs from a container
Print logs and follow them
Print last 5 lines
Print logs and append them with timestamps
Print logs from a certain point in time of container execution (i.e. 23m, 10s, 2013-01-02T13:23:37)
SYNOPSIS
docker logs [OPTIONS] CONTAINER
PARAMETERS
--details
Show extra details provided to logs
-f, --follow
Follow log output (default: false)
--since string
Show logs since timestamp (e.g. '2014-02-27T16:17:33') or relative time (e.g. '42m' for 42 minutes)
-t, --timestamps
Show timestamps (default: false)
--tail string
Number of lines to show from end of logs (default: 'all')
--until string
Show logs before timestamp (e.g. '2013-01-02T13:23:37Z') or relative time (e.g. '42m')
DESCRIPTION
The docker logs command retrieves the logs generated by a Docker container, capturing both stdout and stderr streams from the container's main process and any exec processes. It is essential for debugging, monitoring, and troubleshooting running containers without needing to enter them via docker exec.
Logs are stored by Docker in JSON format on the host filesystem, typically under /var/lib/docker/containers/<container-id>/<container-id>-json.log. The command streams these logs to the terminal, allowing real-time viewing or historical playback.
By default, it shows all logs from container start. Options enable filtering by time (--since, --until), tailing recent lines (--tail), following live output (--follow), or adding timestamps (--timestamps). This makes it invaluable for observing application behavior, error diagnosis, and log analysis in containerized environments.
Supports multi-line log entries and works with stopped containers. Combine with tools like grep or jq for advanced parsing.
CAVEATS
Logs may rotate if container produces excessive output; use log drivers for production. Not suitable for high-volume logging—prefer structured loggers like Fluentd.
EXAMPLE USAGE
docker logs my-container — show all logs.
docker logs -f --tail 100 my-container — tail last 100 lines and follow.
docker logs --since=1h my-container — logs from last hour.
LOG DRIVERS
Container logs use 'json-file' driver by default; configure others (syslog, journald) via docker run --log-driver to affect output.
HISTORY
Introduced in Docker 1.0 (2014); enhanced with --since/--until in 1.13 (2017), --tail improvements in later versions. Evolved alongside Docker CLI for Swarm and Compose integration.
SEE ALSO
docker(1), journalctl(1), tail(1)


