I am running a container on a VM. My container is writing logs by default to /var/lib/docker/containers/CONTAINER_ID/CONTAINER_ID-json.log file until the disk is full.
Currently, I have to delete manually this file to avoid the disk to be full. I read that in Docker 1.8 there will be a parameter to rotate the logs. What would you recommend as the current workaround?
Ad hoc solutionBackup the current log file. Install miscellaneous system utilities. Use fallocate to remove the first 130GiB from the log file. Display the size of the truncated log file.
Docker takes a conservative approach to cleaning up unused objects (often referred to as “garbage collection”), such as images, containers, volumes, and networks: these objects are generally not removed unless you explicitly ask Docker to do so. This can cause Docker to use extra disk space.
To set log limits for containers on a host --log-opt can be configured with max-size and max-file so that a containers logs are rolled over when they reach a max limit and only a certain number of files are saved before being discarded. Hope this helps!
If your system is getting out of disk space and you found that the docker container's log files are consuming high disk space. you can find the log file location and clear them with the help of this tutorial. While clearing log files of a docker container, you don't need to stop it.
Docker 1.8 has been released with a log rotation option. Adding:
--log-opt max-size=50m
when the container is launched does the trick. You can learn more at: https://docs.docker.com/engine/admin/logging/overview/
CAUTION: This is for docker-compose version 2 only
Example:
version: '2' services: db: container_name: db image: mysql:5.7 ports: - 3306:3306 logging: options: max-size: 50m
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With