Docker container logs

docker logs -f: follow a container's logs live

Run docker logs -f web to stream a container's stdout and stderr as new lines arrive; Ctrl+C stops the stream, not the container. --tail defaults to all, so add -n 100 to start from the last 100 lines, or --since 10m to start 10 minutes back.

4 min readLogs and monitoring

At a glance

  • docker logs -f --tail 100 web follows live output, starting from the last 100 lines.
  • --since and --until take relative times like 42m or timestamps like 2026-10-30T08:00:00Z.
  • docker compose logs -f follows every service in a Compose project at once.
  • Empty logs usually mean a different logging driver, an app that writes to files, or Python buffering.

Follow a container's logs

To watch a container's output live, pass -f (or --follow) with the container name or ID from docker ps. docker logs -f web prints the existing output and then streams new lines as they arrive. Ctrl+C stops the docker logs command in your terminal, not the container.

docker logs shows what the container's command writes to stdout and stderr, and --tail defaults to all. If a container has been running for days, dumping the whole history takes a while, so add --tail 100 or -n 100 to print only the last 100 lines before following.

Bash
docker ps --format '{{.Names}}  {{.Image}}  {{.Status}}'
docker logs -f web
docker logs -f --tail 100 web

Filter by time and add timestamps

When you only care about a recent failure or a specific window, filter with --since and --until. Both accept a timestamp like 2026-10-30T08:00:00Z or a relative time like 42m, and you can combine --since with --follow or --tail.

If your application doesn't print its own timestamps, pass -t (or --timestamps) to prefix every line with an RFC3339Nano timestamp.

Bash
docker logs --since 10m -t web
docker logs --since 2026-10-30T08:00:00Z --until 2026-10-30T09:00:00Z web
docker logs -f --since 5m web

Here is the full set of docker logs options:

OptionWhat it doesExample
-f, --followKeeps streaming new outputdocker logs -f web
-n, --tailLines to show from the end, default alldocker logs -n 100 web
--sinceOutput after a timestamp or relative timedocker logs --since 42m web
--untilOutput before a timestamp or relative timedocker logs --until 10m web
-t, --timestampsAdds an RFC3339Nano timestamp to each linedocker logs -t web
--detailsShows extra details provided to logsdocker logs --details web

Docker Compose logs

For multi-container projects, docker compose logs -f follows every service in the Compose file at once and interleaves their lines. To watch only some services, list their names at the end of the command.

  • -n or --tail sets the number of lines per container (default all).
  • --no-log-prefix drops the service name prefix, and --no-color turns off colors.
  • --index picks one container when a service runs several replicas.
  • --since, --until and -t work just like they do in docker logs.
Bash
docker compose logs -f --tail 50 api worker

When docker logs shows nothing

If docker logs prints nothing or fails with an error, the cause is usually the container's logging driver or how the process inside writes and buffers its output.

Check the logging driver

Docker's default logging driver is json-file. docker logs reads the local, json-file and journald drivers directly. With the none driver no logs are kept, and docker logs returns no output at all.

For remote drivers like splunk, Docker Engine turns on dual logging automatically: it keeps a local cache of up to 5 files of 20 MB each per container by default. If an admin disables that cache, docker logs fails with configured logging driver does not support reading. Check which driver a container uses with docker inspect:

Bash
docker inspect -f '{{.HostConfig.LogConfig.Type}}' web

Check where the app writes and whether Python buffers

A web server or database that writes to log files inside the container instead of stdout and stderr won't show up in docker logs. Point its logs at stdout, or read the files with docker exec.

For Python jobs, buffering is the usual culprit. Without a TTY, Python block-buffers stdout, so print() output only reaches docker logs in large chunks or when the container exits. Set PYTHONUNBUFFERED=1 or run python -u; the guide to unbuffered Python output covers the details.

Dockerfile
FROM python:3.12-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /app
COPY . .
CMD ["python", "train.py"]

Watch a long job without the Docker CLI

docker logs -f needs access to the Docker daemon, on the host itself or over SSH with docker -H ssh://user@host. For a long training run or batch job on a remote GPU box or a CI runner, a live link is easier to check from anywhere, as long as the container has outbound HTTPS. tqdml run streams the command's stdout and stderr to a page that keeps the last 500 lines, and still prints everything to docker logs.

FAQ

Does Ctrl+C on docker logs -f stop the container?

No. Ctrl+C only stops the docker logs command in your terminal. The container and its main process keep running.

How do I see only the last 100 lines?

Pass --tail 100 or -n 100, for example docker logs --tail 100 web. By default --tail is all, which prints the entire log history of the container.

How do I stop Docker logs from filling the disk?

The default json-file driver does not rotate logs. Set max-size and max-file under log-opts in daemon.json (as strings, like "10m" and "3"), or switch to the local driver, which Docker recommends to prevent disk exhaustion. Changes in daemon.json only apply to containers created afterwards, so re-create existing ones.

Why do my Python print() calls not show up in docker logs?

Without a terminal, Python block-buffers stdout, so print() output stays in memory until the buffer fills or the process exits. Run python -u or set PYTHONUNBUFFERED=1 in the container to make output unbuffered.

Can I follow the logs of every service in a Compose project at once?

Yes. Run docker compose logs -f in the project directory to follow all services together. To watch a subset, list the service names at the end, and add --tail to limit how many past lines each container prints first.

Check on long runs from your phone

Change one import and every tqdm bar prints a link you can open on any device. Get a Discord or Slack message when the run finishes, fails or stalls.

Get a live linkpip install tqdm-live

Sources