docker system df to see what uses space, then docker system prune to remove stopped containers, unused networks, dangling images and unused build cache. Add -a to also remove every image no container uses. Volumes are kept unless you add --volumes. Large container logs in /var/lib/docker/containers need log rotation instead.
Before you start
- Run the commands as a user in the
dockergroup, or putsudoin front. - Prune means “delete what nothing is using”. Each prune command asks for confirmation unless you add
-f. - If the disk is already 100% full and Docker won’t respond, see fix “No space left on device” first.
How to see what Docker uses
docker system df -v.
docker system df does not count container logs. Check those and the total with:
What does each prune command remove?
How to clean up Docker safely
1
Check what is running
2
Remove unused data
y to confirm. The command ends with Total reclaimed space:.3
Review volumes before deleting them
docker volume rm <name>.4
Check the result
How to stop container logs filling the disk
By default thejson-file log driver keeps logs without a size limit.
1
Set log rotation for all new containers
Create or edit This keeps at most three 10 MB log files per container.
/etc/docker/daemon.json:2
Restart Docker
3
Recreate existing containers
The setting applies only to containers created afterwards. Recreate yours, for example with
docker compose up -d --force-recreate in each Compose project.web with the container name. The old log lines are gone after this.
How to prune Docker automatically
Run a weekly clean-up of anything unused for more than 7 days. Open root’s crontab withsudo crontab -e and add:
Frequently asked questions
Does docker system prune delete my running containers?
No. It removes only stopped containers and data that no container uses. Running containers, their images and their volumes stay.Why is /var/lib/docker still large after pruning?
Usually it is container logs, volumes or images that running containers use. Check logs with thedu command above and volumes with docker system df -v.
Is it safe to delete files in /var/lib/docker by hand?
No. Deleting files there can corrupt Docker. Use the prune andrm commands, or truncate for log files only.
Can I move Docker’s data to a bigger disk?
Yes, setdata-root in /etc/docker/daemon.json to a folder on the new disk and restart Docker; move the existing data first or Docker starts empty. See mount a new disk and manage VPS storage.
Related guides
VPS and dedicated server guides
Every guide in this section.
Find what is using disk space
Track down large folders.
Fix No space left on device
When the disk is already full.
Docker commands cheat sheet
Containers, images and volumes.
Check disk space
df and du explained.
Checked against the official Docker pruning documentation and json-file log driver docs on 4 November 2026; prune,
df, log truncation and daemon.json tested on Ubuntu 24.04 LTS with Docker Engine 29.9.2. Commands can differ between Docker versions.Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026