containers
docker logs
Fetches the stdout/stderr logs of a container. Works with the json-file and local logging drivers; other drivers require querying the destination directly.
docker logs [OPTIONS] CONTAINER Common flags
| Flag | Purpose |
|---|---|
| -f, --follow | Stream new log output as it arrives |
| --tail | Show only the last N lines (or 'all') |
| --since | Show logs since a timestamp or relative time (e.g., 10m) |
| --until | Show logs before a timestamp |
| -t, --timestamps | Prefix each line with a timestamp |
| -n | Alias for --tail |
Examples
docker logs -f web Tail logs live like tail -f
docker logs --tail 100 --timestamps api Last 100 lines with timestamps
docker logs --since 15m worker Only entries from the last 15 minutes
docker logs api 2>&1 | grep ERROR Combine stderr and stdout for grep
Gotcha
Docker logs only works with json-file/local drivers by default. When containers write to files inside themselves (e.g., /var/log/app.log) instead of stdout, docker logs shows nothing — log to stdout/stderr.
Related commands
docker ps
Lists containers along with their status, ports, and identifiers. By default it shows only running containers unless -a is passed.
docker exec
Runs a new command inside an already running container. Commonly used for shells, debugging, or one-off maintenance tasks.
docker inspect
Returns low-level JSON metadata about Docker objects — containers, images, networks, volumes, and more. Supports Go template formatting for extracting specific fields.
docker run
Creates and starts a new container from a specified image in a single step. This is the primary command for launching workloads and supports extensive configuration for networking, storage, and process control.
docker stop
Gracefully stops one or more running containers by sending SIGTERM and then SIGKILL after a timeout. Use docker kill for an immediate SIGKILL.
← All Docker commands · Docker vs Kubernetes · Docker vs VMs