Reputation: 2253
I'm new to docker and didn't know that the logfile size is unlimited.
Now I have 2 containers running which I want to keep, but limit the size of their logfiles (which are larger than 40GB currently).
Is this possible for existing containers, since there is no option using any docker start command.
Upvotes: 3
Views: 2903
Reputation: 4253
I've run into this problem recently as well, (3 containers in particular ate up over 68GB(!)), so I made a few notes for myself; I'll paste them here.
Keep Docker containers from filling up the disk with container logs:
In the 'Advanced' section of the Docker Desktop UI, add this (Max log sizes of 5MB/Max Number of Logs 500, adjust to your preference):
"log-driver": "json-file",
"log-opts": {
"max-size": "5m",
"max-file": "500"
}
Like me, you'll probably also want to clean up your docker VM, of all those logs:
Clean Up Log Files (containers) (SSH into the VM and chroot /host
to do this):
List them:
find /var/lib/docker/containers/ -type f -name "*.log"
From there, choose which to delete by editing the path in the example below. To delete, just add -delete
to the end of your command.
i.e.:
find /var/lib/docker/containers/ -type f -name "*.log" -delete
Last think you might want to do is optimize your Docker VM after cleaning out all that junk:
To Optimize/Shrink the VM (use Powershell):
Mount-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\DockerDesktop.vhdx" -ReadOnly
Optimize-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\DockerDesktop.vhdx" -Mode Full
Dismount-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\DockerDesktop.vhdx"
Upvotes: 2