DEV Community

leroykayanda
leroykayanda

Posted on

Freeing up linux disk space

Check how how much space journal logs are taking up.

sudo journalctl --disk-usage
Archived and active journals take up 4.0G on disk.
Enter fullscreen mode Exit fullscreen mode
sudo du -h --max-depth=1 /var/log/journal | sort -hr
4.1G    /var/log/journal/ec2d0f46985d6ec5013a525e909aa54e
4.1G    /var/log/journal
Enter fullscreen mode Exit fullscreen mode

Keep only 7 days of logs.

sudo journalctl --vacuum-time=7d

Do a docker cleanup.

docker system prune -a
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all images without at least one container associated to them
  - all build cache
Enter fullscreen mode Exit fullscreen mode

Check how much space container logs are taking.

sudo find /var/lib/docker/containers -name "*-json.log" -exec du -h {} + | sort -hr | head

3.1G    /var/lib/docker/containers/ef043adc7a49077b85990e843cb510277b08485d4c024c7cb03f931fd194213f/ef043adc7a49077b85990e843cb510277b08485d4c024c7cb03f931fd194213f-json.log
2.2G    /var/lib/docker/containers/215f590bf565d1c535bde30be7ad157280e1c564f67170f8cacef51a689a106d/215f590bf565d1c535bde30be7ad157280e1c564f67170f8cacef51a689a106d-json.log
231M    /var/lib/docker/containers/d874dba42ab11e04385861601f469f46379bbc99f2d7da22867985a3181ed90a/d874dba42ab11e04385861601f469f46379bbc99f2d7da22867985a3181ed90a-json.log
55M     /var/lib/docker/containers/de870fb1974f6de6d8a502363338d0a877e259c3867211e6de4b71a3f95a969c/de870fb1974f6de6d8a502363338d0a877e259c3867211e6de4b71a3f95a969c-json.log
11M     /var/lib/docker/containers/e492275e03eb43b18388caaaba13f5fe17b2c29abec80edb4f33a193834c3bd7/e492275e03eb43b18388caaaba13f5fe17b2c29abec80edb4f33a193834c3bd7-json.log
11M     /var/lib/docker/containers/91c92b5d9939645bd7b6c802917d527bd63c0357ee6ad8f9519b912dc38554ed/91c92b5d9939645bd7b6c802917d527bd63c0357ee6ad8f9519b912dc38554ed-json.log
8.0K    /var/lib/docker/containers/e96b2115302f415aabf4cb44bfc6ecc80b78dd7afbe8d3a4bd10c9528b692d37/e96b2115302f415aabf4cb44bfc6ecc80b78dd7afbe8d3a4bd10c9528b692d37-json.log
Enter fullscreen mode Exit fullscreen mode

Truncate them safely (no container restart)

sudo truncate -s 0 /var/lib/docker/containers/*/*-json.log

Top comments (0)