By default, at least in Ubuntu, Docker container logs will grow indefinitely (in my case up to 412 GB, thus filling up my hard drive).
To prevent this, you can create a /etc/docker/daemon.json
file with the following configuration:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
Don't forget to restart the Docker service afterwards, and in my case I had to do the following as well:
$ sudo systemctl restart docker
$ docker-compose down # this destroyed all my nice containers, but without it, they wouldn't accept the log config (maybe there's a better solution?)
$ docker-compose up -d
$ docker-compose down # this destroyed all my nice containers, but without it, they wouldn't accept the log config (maybe there's a better solution?)
$ docker-compose up -d
Finally, to check that the config was successful, for any of the containers that are running you can do this: (remember to replace the container ID)
$ docker inspect 3fa6f8fd01d6 | jq '.[0].HostConfig.LogConfig'
{
"Type": "json-file",
"Config": {
"max-file": "3",
"max-size": "10m"
}
}
{
"Type": "json-file",
"Config": {
"max-file": "3",
"max-size": "10m"
}
}
Final thoughts
Why would the default Docker configuration not have a log size limit‽ This makes zero sense to me.