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?
Pass log options while running a container. An example will be as follows
where
--log-opt max-size=5m
specifies the maximum log file size to be 5MB and--log-opt max-file=10
specifies the maximum number of files for rotation.Caution: this post relates to docker versions < 1.8 (which don't have the
--log-opt
option)Why don't you use logrotate (which also supports compression)?
Configure it either directly on your CoreOs Node or deploy a container (e.g. https://github.com/tutumcloud/logrotate) which mounts /var/lib/docker to rotate the logs.
Docker 1.8 has been released with a log rotation option. Adding:
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: