This error occurs when Docker container logs grow too large because log rotation is not configured. The fix involves configuring the json-file logging driver with max-size and max-file options to enable automatic log rotation.
The "error reading log file: file size exceeds limit" error in Docker indicates that a container's log file has grown so large that Docker cannot read it efficiently. This typically happens when using Docker's default json-file logging driver without log rotation configured. By default, Docker's json-file logging driver does not perform any log rotation. Container stdout and stderr output is written to JSON files located in `/var/lib/docker/containers/<container-id>/<container-id>-json.log`. Without limits, these files grow indefinitely until they consume all available disk space. This error commonly appears when trying to view logs with `docker logs` for a container that has been running for a long time and producing significant output. The Docker daemon imposes internal limits on log file reads to prevent memory exhaustion.
First, find which container is generating large logs:
# List containers with their log paths
docker inspect --format='{{.Name}} {{.LogPath}}' $(docker ps -aq)
# Check log file sizes
sudo du -sh /var/lib/docker/containers/*/*-json.log | sort -h
# Or check a specific container's log size
docker inspect --format='{{.LogPath}}' <container_id> | xargs sudo ls -lhThis helps you identify which containers need log rotation configured.
To immediately free up disk space without stopping the container, truncate the log file:
# Get the log file path for your container
LOG_PATH=$(docker inspect --format='{{.LogPath}}' <container_id>)
# Truncate the log file (clears contents but keeps file)
sudo truncate -s 0 "$LOG_PATH"
# Alternative using cat
sudo cat /dev/null > "$LOG_PATH"Note: This only provides temporary relief. Without configuring log rotation, the file will grow again.
Set up log rotation for all new containers by editing the Docker daemon configuration:
# Create or edit daemon.json
sudo nano /etc/docker/daemon.jsonAdd the following configuration:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}This limits each log file to 10MB and keeps 3 rotated files (30MB total per container).
Restart Docker to apply the changes:
sudo systemctl restart dockerImportant: Existing containers will NOT use the new configuration. They must be recreated.
When starting containers manually, specify log options:
docker run -d \
--log-driver json-file \
--log-opt max-size=10m \
--log-opt max-file=5 \
your-image:tagCommon max-size values:
- Development: 10m (10 megabytes)
- Production: 50m-100m
- High-volume logging: 200m with max-file=10
Add logging configuration to each service in your docker-compose.yml:
version: '3.8'
services:
app:
image: your-app:latest
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "5"
database:
image: postgres:15
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "3"After updating, recreate the containers:
docker-compose down
docker-compose up -dExisting containers must be recreated to use new log settings:
# For docker-compose
docker-compose down
docker-compose up -d
# For standalone containers, stop and remove, then run with new settings
docker stop <container_id>
docker rm <container_id>
docker run -d --log-opt max-size=10m --log-opt max-file=3 your-image:tagVerify the new settings are applied:
docker inspect --format='{{.HostConfig.LogConfig}}' <container_id>After recreating containers, verify log rotation is configured:
# Check container's log configuration
docker inspect <container_id> --format='{{json .HostConfig.LogConfig}}' | jq
# Monitor log file sizes over time
watch -n 60 'sudo du -sh /var/lib/docker/containers/*/*-json.log | sort -h'You should see multiple rotated log files like:
- <container-id>-json.log (current)
- <container-id>-json.log.1 (rotated)
- <container-id>-json.log.2 (rotated)
Using the local logging driver: Docker recommends the local logging driver for production as it performs log rotation by default and uses a more efficient binary format:
{
"log-driver": "local",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}Note: The local driver's logs are not in JSON format, so docker logs output format differs slightly.
Centralized logging solutions: For production environments, consider using dedicated logging drivers that ship logs to external systems:
- syslog - System logging daemon
- journald - systemd journal
- fluentd - Forward to Fluentd collector
- awslogs - Amazon CloudWatch Logs
- gcplogs - Google Cloud Logging
Application-level logging: Instead of relying solely on Docker log rotation, consider:
- Configuring your application to rotate its own logs
- Logging to a file volume instead of stdout
- Using structured logging with log levels to reduce volume
Kubernetes environments: If using Docker with Kubernetes, note that kubelet handles log rotation separately. Configure it via the containerLogMaxSize and containerLogMaxFiles kubelet flags.
Compression: The json-file driver supports compression with the compress option:
{
"log-opts": {
"max-size": "10m",
"max-file": "5",
"compress": "true"
}
}Windows considerations: On Windows Server, daemon.json is located at C:\ProgramData\docker\config\daemon.json. Docker Desktop for Windows uses a virtual machine, so log paths differ.
Error response from daemon: client version X.XX is too new. Maximum supported API version is X.XX
How to fix 'client version is too new' in Docker
dial tcp: i/o timeout
How to fix 'dial tcp: i/o timeout' in Docker
image operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker
cannot open '/etc/passwd': Permission denied
How to fix 'cannot open: Permission denied' in Docker