Skip to content
Lesson: docker logsSwitch
← DevOps Operations

Delivery and containers

docker logs

Read, follow and filter the output of containers to find out what went wrong.

docker logs shows what a container's main process wrote to standard output and standard error (if the container was started with a terminal, docker run -t, the two are merged). It is usually the first place to look when something fails.

Basic use

$ docker run -d --name ticker alpine sh -c 'while true; do echo tick; sleep 2; done'
$ docker logs ticker
tick
tick
tick

Use the container name or ID. It also works after the container has stopped, as long as you have not removed it. A container started with --rm takes its logs with it when it exits.

Follow live output

$ docker logs -f ticker

-f keeps printing new lines. Press Ctrl+C to stop watching. This does not stop the container.

Show less

$ docker logs --tail 20 ticker
$ docker logs --since 10m ticker

--tail (or -n) limits output to the last lines. --since shows entries newer than a time, either relative like 10m or a timestamp. --until sets the other end. You can combine them with -f:

$ docker logs -f --tail 5 ticker

Add -t to put a timestamp before each line:

$ docker logs -t --tail 1 ticker
2026-03-04T10:15:22.123456789Z tick

Search the output

Your program's error stream comes out on the error stream of docker logs, so a pipe alone misses it. Redirect it first:

$ docker logs web 2>&1 | grep -i error

The streams lab explains 2>&1.

When the logs are empty

If an application writes only to a file inside the container, docker logs will not show it. Many official images send their logs to the standard streams for this reason.

The logging driver decides where output goes. The default is json-file. With some other drivers or settings, reading logs locally may not work. By default json-file does not rotate, so a noisy container can fill the disk; set max-size and max-file options.

See the docker logs reference.

Try it

Run the ticker container, follow it, press Ctrl+C, and check with docker ps that it is still running. Then remove it with docker rm -f ticker.

Check your understanding

docker logs

All 4 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.