Show a Container's Logs
docker logs web
This prints everything the main process of the container web wrote to standard output and standard error since the container was created. It works for stopped containers too, which helps when a container exits right after it starts. The logs belong to the container: when you remove the container, its logs go with it.
Follow, Limit, and Filter
| Option | Example | What it does |
|---|---|---|
-f | docker logs -f web | Keeps printing new lines |
--tail | docker logs --tail 100 web | Last 100 lines only |
--since | docker logs --since 30m web | Last 30 minutes |
--until | docker logs --until 1h web | Lines older than an hour |
-t | docker logs -t web | Adds timestamps |
The options combine: docker logs -f --tail 50 web shows the last 50 lines and then follows. --since and --until take relative times such as 10m or 2h, or a timestamp such as 2026-11-28T09:00:00Z; without the Z or an offset, the time is read in your local time zone. Ctrl+C stops following and leaves the container running. Following a log file on the host works the same way with tail -f.
Search the Logs: stdout and stderr
docker logs writes what the container sent to standard output to your standard output, and its error stream to your error stream. A plain pipe passes only the first one, so grep seems to miss error messages. Join the two streams first:
docker logs web 2>&1 | grep -i error
docker logs web 2>/dev/null
docker logs web >/dev/null
The second line shows standard output only, the third shows errors only. To search for several words at once, see how to grep multiple strings.
Logs of a Compose Project
docker compose logs
docker compose logs -f --tail 50 web
docker compose logs --since 1h db
Run these in the project folder. Without a service name, Compose merges the output of all services and starts each line with the service name. The same options as for docker logs apply.
Where Docker Stores the Logs
The default logging driver is json-file: Docker writes each container's output to a JSON file on the host. Check the default and the file of one container:
docker info --format '{{.LoggingDriver}}'
docker inspect --format '{{.LogPath}}' web
With the default data folder, the path lies under /var/lib/docker/containers. Docker's documentation says these files are meant to be accessed by the daemon only: read them with docker logs, and do not edit or delete them. Other drivers exist: local stores a compact format and rotates its files by default, and journald sends the output to the systemd journal, where sudo journalctl CONTAINER_NAME=web reads it, as described in the journalctl guide. docker logs reads json-file, local, and journald directly; for other drivers Docker keeps a local cache copy that it can read, unless that cache is turned off.
Stop Log Files from Filling the Disk
With the json-file driver and no options, Docker keeps every line without a size limit. A busy container can fill the disk over months. Set a limit for new containers in /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
Each container then keeps at most three files of 10 MB. The values must be strings in quotes. If the file already exists, add the keys to it: one syntax error stops Docker from starting. Check the file, then restart Docker:
sudo dockerd --validate
sudo systemctl restart docker
Unless live-restore is enabled in daemon.json (it is off by default), the restart stops the running containers; those with the restart policy always or unless-stopped start again, the others stay stopped. The new limits apply only to containers created afterwards. Existing containers keep their old settings until you recreate them, for example with docker compose up -d --force-recreate.
Limits for One Container or Service
docker run -d --name web --log-opt max-size=10m --log-opt max-file=3 nginx:1.30
In a Compose file:
services:
web:
image: nginx:1.30
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
When docker logs Shows Nothing
- The program logs to files: it writes inside the container instead of to its output. The official Nginx image links its log files to the output; for other programs, change their log setting or read the files with
docker exec. - The container was replaced: the logs went with the old container.
- Another driver is set: with a driver that sends logs elsewhere, read them where they are sent.