On this page
- How do you read the output of a container?
- Why do Docker logs fill the disk?
- How do you set global log limits in daemon.json?
- What does the local driver offer?
- How do you set limits for one container or service?
- How do you send container logs to journald?
- How do you empty a log that is already huge?
- What if docker logs shows nothing?
- Questions
How do you read the output of a container?
The docker logs command shows everything a container wrote to standard output and standard error, which is where well behaved images send their messages. It works with a container name or id, running or stopped:
docker ps --format 'table {{.Names}}\t{{.Status}}'
docker logs web
docker logs -f --tail 50 web # last 50 lines, then follow
docker logs --since 30m web # only the last 30 minutes
docker logs --since 2026-12-01T08:00:00 --until 2026-12-01T09:00:00 web
docker logs -t web 2>&1 | grep -i errorThe -t flag adds timestamps when the application does not print its own. Notice the 2>&1 before the pipe: docker logs replays the container error stream on your own standard error, so without it grep misses those lines. With Compose, docker compose logs -f merges all services and colours each name, as described in the Compose guide. If you have not installed Docker yet, start with the Docker Engine tutorial.
Why do Docker logs fill the disk?
The default logging driver, json-file, appends every line to a file under /var/lib/docker/containers/ID/ and, unless you configure it, never rotates or trims that file. A chatty container that runs for months can grow a log of many gigabytes and silently eat the disk of a small VPS. Find the biggest offenders like this:
docker info --format '{{.LoggingDriver}}'
sudo du -h /var/lib/docker/containers/*/*-json.log | sort -h | tail
docker inspect --format '{{.LogPath}}' webThe first command tells you which driver new containers get. The last one prints the exact file behind one container, so you can match a large file to a name.
How do you set global log limits in daemon.json?
Create or edit /etc/docker/daemon.json with a size cap and a file count. Values must be strings, in quotes, or the daemon refuses to start:
sudo nano /etc/docker/daemon.json{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "5",
"compress": "true"
}
}That keeps at most five files of 10 MB per container, older ones gzipped. Validate the JSON, then restart the service:
sudo dockerd --validate --config-file /etc/docker/daemon.json
sudo systemctl restart docker
systemctl status docker --no-pagerRestarting Docker stops running containers briefly; those with a restart policy come back by themselves. The new settings only reach containers created afterwards, so recreate existing ones, for example with docker compose up -d --force-recreate. Check one container with docker inspect --format '{{.HostConfig.LogConfig}}' web.
What does the local driver offer?
The local driver stores logs in a compact binary format and rotates by default (about 100 MB per container in five files), so it is a sound choice when you never read the raw files with other tools. Switch to it with "log-driver": "local" in daemon.json, optionally with your own max-size. Reading still works through docker logs. Keep json-file if a log shipper on the host tails the JSON files directly, because the local format is not meant for outside readers.
How do you set limits for one container or service?
Per-container options override the global default, which helps when one noisy service needs a tighter cap:
docker run -d --name worker \
--log-opt max-size=5m --log-opt max-file=3 \
myimage:1.0In Compose, add a logging block to the service:
services:
worker:
image: myimage:1.0
logging:
driver: json-file
options:
max-size: "5m"
max-file: "3"Recreate the service after the change with docker compose up -d; Compose notices the new logging settings and replaces the container.
How do you send container logs to journald?
The journald driver writes each line into the systemd journal with fields such as the container name, which gives you one place for host and container messages and lets journald handle rotation. Enable it for all new containers:
{
"log-driver": "journald"
}Restart Docker, recreate containers, and read with journalctl using the container fields:
journalctl CONTAINER_NAME=web -f
journalctl CONTAINER_NAME=web --since "1 hour ago" -o cat
docker logs --tail 20 webThe journal limits its own size; set an explicit ceiling in /etc/systemd/journald.conf with a line such as SystemMaxUse=500M, then run sudo systemctl restart systemd-journald. On some Debian and Ubuntu images the journal is kept only in memory until /var/log/journal exists; create that directory for logs that survive a reboot. The journalctl guide covers filters in more depth.
How do you empty a log that is already huge?
For an emergency, truncate the JSON file in place rather than deleting it, because Docker keeps the file open and a deleted file keeps using space until the container stops:
sudo truncate -s 0 "$(docker inspect --format '{{.LogPath}}' web)"
df -h /This loses the old lines, so save anything you need first with docker logs web > /srv/web-old.log 2>&1. Then add limits as above so it does not happen again. If the disk is full for other reasons as well, the Docker cleanup guide and the disk usage guide help you find the rest.
What if docker logs shows nothing?
An empty result usually means the application writes to a file inside the container instead of to standard output. Look for it with docker exec web ls /var/log, or check the image documentation for an option that logs to the console. Official images often link their log files to /dev/stdout for this reason. If the driver is set to none, nothing is kept at all; docker inspect shows the active driver per container. Since Docker Engine 20.10, docker logs also reads from a small local cache when a remote driver such as syslog is in use, so short history is still visible.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Read and limit Docker logs
Do new log settings apply to running containers?
No. Logging options are fixed when a container is created. After changing daemon.json and restarting Docker, recreate each container to pick them up.
What is a sensible max-size on a small VPS?
Something like 10 MB with 3 to 5 files per container keeps recent history while leaving the disk for data. Raise it for services where you often need older lines.
Can I use journald and still run docker logs?
Yes. The journald driver supports docker logs, so both commands show the same lines.
Does the restart of Docker lose my container data?
No. Containers are stopped and started again; volumes and images stay. Containers without a restart policy stay stopped until you start them.
How do I rotate logs that my app writes to files?
Mount that directory to the host and let logrotate handle it, or change the app to log to standard output so the Docker driver limits apply.
More in Containers and PaaS
- Docker Compose stacks
- Docker volumes and bind mounts
- Free disk space used by Docker
- Build, tag and push Docker images
- Run and manage containers
- Podman and rootless containers
- Docker Swarm across servers
- Automatic updates with Watchtower
- Portainer CE web UI
- Dokploy self-hosted PaaS
- CapRover PaaS
- Dokku git push deploys
- Coolify on your own server