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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

docker logs [OPTIONS] CONTAINER

Parameters

ParameterDescription
--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

The last lines, including stderr
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.

Logs survive until the container is removed
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.

Was this page helpful?