Why Can Docker Logs Fill Up Your Entire Disk?
I recently ran into an interesting infrastructure issue while managing Docker containers on a Raspberry Pi.
The disk was running out of space, and after investigating, I discovered that Docker container logs were consuming a surprisingly large amount of storage.
One container's JSON log file alone had grown to over 100 GB!
Why does this happen?
By default, Docker uses the json-file logging driver.
Whenever a container writes something to stdout or stderr, Docker captures that output and stores it in a JSON log file on the host.
For example, an application that continuously prints debug messages, errors, or request information can generate gigabytes of logs over time.
The problem is that Docker's default json-file logging configuration doesn't impose a size limit or automatic rotation.
So the logs just keep growing.
How do you fix it?
Docker supports log rotation through the max-size and max-file options.
You can configure these globally in /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}}
This configuration tells Docker to:
- Rotate a log file once it reaches 10 MB.
- Keep a maximum of 3 log files per container.
After updating the configuration, restart Docker and recreate existing containers for the new logging configuration to apply.
How I investigate Docker disk usage
A few useful commands:
# Check Docker disk usage
docker system df
# Find large container logs
sudo du -ah /var/lib/docker/containers | sort -rh | head -20
# Inspect a container's logging configuration
docker inspect <container_name> \ --format '{{.HostConfig.LogConfig}}'
The takeaway
Docker containers may be isolated, but their logs still consume storage on the host machine.
If you're running Docker on a Raspberry Pi, VPS, or any production server, log rotation should be part of your initial setup rather than something you discover when your disk fills up.