Docker Engine 29 reference · Containers
docker logs Command (Docker CLI)
Show what a container wrote to stdout and stderr, optionally only the last lines, with timestamps, or following new output.
Docker Engine 29
Syntax
docker logs [OPTIONS] CONTAINER
Parameters
| Parameter | Description |
|---|---|
--tail N |
Only the last N lines. |
-f |
Follow new output. |
--since TIME |
Only logs since a time or duration (e.g. 10m). |
-t |
Show timestamps. |
Examples
docker run --name rc-ref-logs alpine:3.24 sh -c 'for i in 1 2 3 4; do echo line $i; done; echo oops >&2' > /dev/null 2>&1
docker logs --tail 2 rc-ref-logs 2>&1
docker rm rc-ref-logs > /dev/null
Output
line 4 oops
Run this on your computer — see “Get Started” for setup.
docker run --name rc-ref-logs2 alpine:3.24 echo started > /dev/null
echo "stdout only: $(docker logs rc-ref-logs2 2>/dev/null)"
docker rm rc-ref-logs2 > /dev/null
Output
stdout only: started
Run this on your computer — see “Get Started” for setup.
docker logs writes the container's stdout to stdout and its stderr to stderr, so redirect 2>&1 when piping. It works for the json-file, local and journald log drivers.
Related
docker run· Create and start a container from an image, with options for ports, environment, volumes, names and cleanup.docker exec· Run an extra command inside a running container, for example a shell for debugging or a one-off task.- Logs, exec and inspect · tutorial