Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
DevOps

Docker Compose logs: read, filter and keep them in check

Read, follow and filter Docker Compose logs with the right flags, pick a logging driver that rotates, and learn why a container's log can come back empty.

CloudSat teamNovember 18, 20266 min read
Parallel ribbons of glowing text lines flowing out of stacked containers into a single funnel
On this pageWhere the lines come from

When a Compose stack misbehaves, docker compose logs is the first command most people type and the one they use least well. A few flags turn a wall of interleaved output into the ten lines that explain the problem. A few settings stop those same logs from filling the disk. This guide covers both, plus the cases where the log is simply empty.

Where the lines come from

Docker captures whatever each container writes to standard output and standard error. A logging driver stores those streams, and docker compose logs asks the driver to read them back for every container in the project.

Two consequences follow:

  • An application that writes to a file inside the container, such as /var/log/app.log, produces nothing in docker compose logs. Well-built images avoid this. The official nginx image, for example, links its access and error logs to stdout and stderr.
  • Logs belong to a container, not to a service. When Compose recreates a container during up -d or removes it with down, the old container's log goes with it unless a driver sent it somewhere else.

Reading logs with docker compose logs

Run the command from the directory that holds compose.yaml, or point to it with -f. With no arguments it prints the full history of every service, which is rarely what you want.

Flag What it does
-f, --follow Keep streaming new lines
-n, --tail N Start with the last N lines per container (default: all)
--since, --until Limit by time, absolute (2026-11-18T09:00:00) or relative (15m)
-t, --timestamps Prefix each line with Docker's receive timestamp
--no-log-prefix Drop the service name printed before each line, useful before piping
--no-color Plain output for files and grep
--index N Pick one replica of a scaled service

The everyday combinations:

docker compose logs -f --tail 50 web            # watch one service live
docker compose logs --since 30m web worker      # two services, last half hour
docker compose logs -t --since 10m db           # timestamps help match events
docker compose logs --index 2 worker            # the second replica only

Service names come from compose.yaml, not from container names. If you are unsure what is running, docker compose ps -a lists every container in the project, including ones that have exited.

Searching and saving

The output pipes like any other text. Strip colors and prefixes first so patterns match cleanly:

docker compose logs --no-color --no-log-prefix web | grep -iE "error|timeout"
docker compose logs --no-color --since 2h > incident-$(date +%F).log
docker compose logs --no-log-prefix api | jq -r 'select(.level=="error") | .msg'

The last line assumes the app logs one JSON object per line, which is worth asking for in any service you write yourself: structured logs turn grep guesswork into exact queries.

One trap when you switch to the single-container command docker logs: it sends the container's stderr to your terminal's stderr, so add 2>&1 before piping to grep, or half the messages vanish from the results.

Pick a logging driver deliberately

The driver decides where logs live, how big they get and whether they survive the container.

Driver Rotation Good for
json-file (default) None unless you configure it Nothing long-term; it grows until the disk is full
local Yes, 20 MB per file and 5 files by default, compressed Most single servers
journald Handled by the system journal Hosts already managed with journalctl
syslog, gelf, fluentd Handled by the receiver Shipping to a central log server

Since Docker Engine 20.10, docker logs and docker compose logs can read containers that use remote drivers through a local cache called dual logging, so switching to a shipping driver no longer blinds the CLI.

Set rotation per service

Compose accepts a logging block on each service. This caps one noisy worker without touching anything else:

services:
  worker:
    image: ghcr.io/example/worker:1.4
    logging:
      driver: local
      options:
        max-size: "10m"
        max-file: "3"

To change the default for every new container on the host, set log-driver and log-opts in /etc/docker/daemon.json and restart Docker; the Docker Engine install guide shows the file. Either way, existing containers keep their old settings until you recreate them:

docker compose up -d --force-recreate

Using journald

With driver: journald, each line lands in the system journal tagged with container metadata, and the usual filters work:

journalctl CONTAINER_NAME=shop-web-1 -f
journalctl CONTAINER_NAME=shop-db-1 --since "1 hour ago" -p err

The journal's own size limits (SystemMaxUse in journald.conf) then apply to container logs too, and logs survive container removal until the journal rotates them.

When the log is empty or wrong

Most "no logs" mysteries have one of five causes.

  1. The app writes to a file. Point it at stdout, or run a sidecar that tails the file. Check with docker compose exec web ls -l /var/log.
  2. Output is buffered. Python holds stdout in a buffer when it is not a terminal, so lines appear in bursts or not at all before a crash. Set PYTHONUNBUFFERED=1 in the service's environment.
  3. The container was recreated. A fresh container starts with an empty log. Look for the previous one with docker compose ps -a before it is pruned.
  4. The driver is none, or a remote driver with the cache disabled. Check with docker inspect --format '{{.HostConfig.LogConfig}}' shop-web-1.
  5. Rotation already dropped it. With three 10 MB files, a service that logs every request may keep only minutes of history. Raise the limits or ship the logs out.

For a crash loop, combine the restart count with the last lines before each exit:

docker inspect --format '{{.RestartCount}} restarts, last exit {{.State.ExitCode}}' shop-api-1
docker compose logs --tail 40 api

When one server is no longer enough

Reading logs per host works while you have one or two servers. Once a request crosses several machines, or you need history older than your rotation window, ship everything to one place and search it there. The centralized logging guide compares the lightweight options that fit on a single small server.

FAQ

Where are the log files, and how do I clear a huge one?

With the json-file driver, each container's log sits at /var/lib/docker/containers/<id>/<id>-json.log, and docker inspect --format '{{.LogPath}}' shop-web-1 prints the exact path. As an emergency fix, sudo truncate -s 0 on that path empties the file without stopping the container. Then configure rotation so it does not happen again. Other drivers use their own formats, so read them through the CLI.

Do logs survive docker compose down?

No. down removes the containers, and their logs go with them. Use stop if you only want to pause the stack, or a driver such as journald or a central log server if history matters.

Is there a web view for these logs?

Dozzle is a small open-source viewer that streams container logs to a browser in real time. It reads the Docker socket, so publish it on 127.0.0.1 behind a reverse proxy with authentication; it is also available as a one-click app on CloudSat if you would rather not install it by hand.

Why are timestamps from -t different from the app's own?

The -t timestamp is when Docker received the line, in UTC. The app's timestamp is whatever it printed, often in local time. Comparing both quickly reveals a container with a wrong time zone.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.