This project uses the default Docker json-file logging driver, configured with log rotation to retain logs for approximately 7 days.
Docker containers by default log all output to a file on the host machine. Over time, these logs can grow very large unless you configure rotation.
We use Docker Compose to define logging options that:
- Limit log file size
- Retain a fixed number of rotated log files (approximating 7 days)
The logging driver and options are defined in docker-compose.yml:
services:
myapp:
image: myapp-image
container_name: myapp
logging:
driver: json-file
options:
max-size: "10m"
max-file: "7"max-size: "10m": Each log file will be capped at 10 megabytes.max-file: "7": Docker will keep 7 log files before deleting the oldest.- This provides approximately 7 days of logs assuming ~10MB per day.
docker-compose up -ddocker logs myappIf you update the logging settings, you must recreate the container for the changes to take effect:
docker-compose down
docker-compose up -dDocker does not update logging configs on existing containers.
- Logs are stored in
/var/lib/docker/containers/<container-id>/on the host. - If you need to retain logs for longer than 7 days or archive them externally, consider using a centralized logging system (e.g., Fluent Bit, ELK Stack, or AWS CloudWatch).
- If logs aren't rotating, ensure the container was recreated after logging config changes.
- To confirm log settings, run:
docker inspect myapp | grep -A 5 LogConfig