1) Typical Symptoms
- Docker no longer starts
aptfails
sort,journalctl,systemctlfail
- Errors such as:
No space left on devicecannot create temporary file in /tmpCannot connect to the Docker daemon
2) Quick diagnosis: confirm that the disk is full
Check total disk space
df -h
Watch for:
/at 95-100%
/varvery full
3) If /tmp is full: avoid commands that use sort
When the disk is too full, commands such as:
du ... | sort ...
may fail because
sort uses /tmp.Example of an error:
sort: cannot create temporary file in '/tmp': No space left on device
4) Identify the largest folders (without scanning the entire system)
(Cleaning up Docker first can help)
Scan only /var (often the culprit)
sudo du -h --max-depth=1 /var 2>/dev/null
Then drill down into the largest folder
Example if
/var/lib is huge:sudo du -h --max-depth=1 /var/lib 2>/dev/null
Example if
/var/log is huge:sudo du -h --max-depth=1 /var/log 2>/dev/null
Simple sort (if there’s enough space)
sudo du -h --max-depth=1 /var 2>/dev/null | sort -hr
Top 20
sudo du -h --max-depth=1 /var 2>/dev/null | sort -hr | head -n 20
5) Common issue: systemd-journald logs are too large
If you see a large directory such as:
/var/log/journal/<id_machine>/
Check the log size
sudo du -sh /var/log/journal/*
Clean it up, keeping only 100MB
sudo journalctl --vacuum-size=100M
Or keep only the logs from the last 24 hours:
sudo journalctl --vacuum-time=1d
6) Common issue: huge Docker logs (containers/*.log)
Check the size
sudo du -sh /var/lib/docker/containers
Clear the logs without deleting the containers
sudo find /var/lib/docker/containers/ -name "*.log" -exec truncate -s 0 {} \;
It’s safe: it clears the logs but keeps the files.
7) Restart Docker
After freeing up space:
sudo systemctl restart docker
If it fails:
sudo systemctl status docker journalctl -xeu docker.service
8) Docker diagnostics: understanding what’s taking up space
Once Docker is running:
docker system df
Example output:
- Huge images
- A lot of reclaimable space
9) Docker cleanup (with verification)
View stopped containers
docker ps -a -f "status=exited"
View dangling images
docker images -f "dangling=true"
View unused volumes
docker volume ls -f "dangling=true"
10) Docker cleanup (actions)
Delete stopped containers
docker container prune -f
Delete unused images (dangling only)
docker image prune -f
Delete all unused images (frees up a lot of space)
⚠️ May force re-pulls later.
docker image prune -a -f
Delete unused volumes
docker volume prune -f
Complete (aggressive) cleanup
⚠️ Deletes unused images/volumes.
docker system prune -a -f --volumes
11) Verify that everything is OK after cleanup
Check disk space
df -h
Check Docker
docker system df docker ps
Prevention (recommended)
A) Limit systemd-journald logs
Edit:
sudo nano /etc/systemd/journald.conf
Add or modify:
SystemMaxUse=1G
Then apply:
sudo systemctl restart systemd-journald
B) Automate a weekly Docker cleanup
Create a script
sudo nano /usr/local/bin/docker-prune.sh
Content:
#!/bin/bash docker image prune -a -f docker container prune -f docker volume prune -f docker builder prune -f
Make executable:
sudo chmod +x /usr/local/bin/docker-prune.sh
Add a cron job (Sunday at 3 a.m.)
sudo crontab -e
Add:
0 3 * * 0 /usr/local/bin/docker-prune.sh
C) Limit the size of Docker logs (recommended)
Configure Docker to limit log size.
Create / edit:
sudo nano /etc/docker/daemon.json
Content:
{ "log-driver": "json-file", "log-opts": { "max-size": "50m", "max-file": "3" } }
Restart Docker:
sudo systemctl restart docker
Emergency checklist (summary)
When the VPS is full:
df -h sudo du -h --max-depth=1 /var sudo du -h --max-depth=1 /var/log sudo journalctl --vacuum-size=100M sudo find /var/lib/docker/containers/ -name "*.log" -exec truncate -s 0 {} \; sudo systemctl restart docker docker system df docker image prune -a -f
Important notes
truncate -s 0is safe: it clears the logs without disrupting services.
docker system prune -a --volumesis effective but aggressive.
- If too many images are deleted, Docker will have to re-download them.