Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker container logs taking all my disk space

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?

like image 293
poiuytrez Avatar asked Aug 05 '15 10:08

poiuytrez


People also ask

How do I reduce the size of a docker container log?

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.

Why is docker using so much disk space?

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.

How do I limit container logs?

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!

Can I delete docker log?

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.


2 Answers

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/

like image 138
poiuytrez Avatar answered Oct 19 '22 10:10

poiuytrez


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 
like image 31
jaks Avatar answered Oct 19 '22 09:10

jaks