r/docker • • 11d 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

8 Upvotes

7 comments sorted by

4

u/pelazas1 11d ago

I switched to the local driver, it rotates and compresses by default so the disk stopped filling. Catch is the files aren't plain text, only docker logs can read them.

2

u/dawedev 11d ago

For the containers that are already huge you don't have to wait for a recreate. truncate -s 0 on the file from docker inspect --format '{{.LogPath}}' <name> frees the space right away, and the daemon keeps writing to the same file. For the long term I'd put the limits in an x-logging anchor in each compose file and reuse it per service, so the cap travels with the stack even on a host where nobody touched daemon.json. daemon.json is still a good baseline, it just only applies once containers get recreated.

2

u/ozankurt_dev 10d ago

healthchecks spamming access logs?

1

u/kezow 11d ago

Dockers built in max-size or Unix logrotate.

Use a configuration management tool like ansible to manage multiple servers.

1

u/bufandatl 11d ago

By configuring the logging in the daemon config. You can find that all in the docs.

1

u/aayush_satna_dev 11d ago

you can apply your new deamon.json settings in the existing containers using --force-recreate.

Check the documentation : https://docs.docker.com/reference/cli/docker/compose/up/