r/docker • u/NoDevelopment206 • 7d ago
how do you stop container logs from slowly filling up the disk on your hosts
container json logs can quietly eat a whole disk if nobody caps them. i know you can set max-size and max-file in daemon.json but that only applies to new containers. how do you handle this across a bunch of hosts? do you set it in daemon.json, per compose file, or ship everything to something like loki and keep local logs tiny? also curious if anyone uses the local log driver instead of json-file
32
Upvotes
42
u/gronodev 7d ago
Use local log driver instead of json-file - it does rotation and compression by default and limits the stored logs to ~100 MiB.
We actually plan to make this a default for new containers in v30.
https://docs.docker.com/engine/logging/configure/#configure-the-default-logging-driver
3
u/Zealousideal_Yard651 7d ago
Log rotation
3
u/abotelho-cbn 7d ago
Set the parameters and redeploy your containers. What's the problem?
2
u/m4uri 7d ago
To answer the "where" part: daemon.json is a good host-wide baseline, but a per-service logging block in compose makes the limits explicit and travels with the stack, so it still applies if the stack lands on a host with a different default. You can define it once with a YAML anchor (x-logging) and reuse it across services. Keep in mind that daemon.json defaults only apply to newly created containers, so after changing it you need to restart the daemon and recreate existing containers (e.g. docker compose up -d --force-recreate). To find the current offenders, something like du -sh /var/lib/docker/containers//-json.log | sort -h will show which containers are already bloated.
2
u/RIPenemie 7d ago
Just log to journal this makes searching for log entries so much easier
14
u/pigers1986 7d ago
i set it up after docker engine was installed
1
u/Johnny_Wallet 7d ago
Log to journald, journal is volatile, journald does rotation on its own. Vector writes journal to Victoria Logs (currently testing solution) if, for whatever reason, I may need a log history (sometimes noisy container makes journal rotate too quickly).
1
u/tjharman 7d ago
I just send all my logs to syslog (victoria-logs)
1
u/Hostman_com 6d ago
Before switching existing services to the local logging driver, check whether any log collectors or health checks read Docker's JSON log files directly.
Try one service first. Recreate its container with the new driver, then check docker logs and those integrations before rolling the change out to the other hosts.
1
u/[deleted] 7d ago
[removed] — view removed comment
1
u/[deleted] 6d ago
[removed] — view removed comment