Skip to main content
To free Docker disk space, run 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 docker group, or put sudo in 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

RECLAIMABLE is what prune can free. For a per-image, per-container and per-volume list, run 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

Start any container you want to keep that is currently stopped, so its image and data count as in use.
2

Remove unused data

Type y to confirm. The command ends with Total reclaimed space:.
3

Review volumes before deleting them

These volumes are not attached to any container. Delete one you are sure about with docker volume rm <name>.
4

Check the result

docker volume prune -a, docker system prune --volumes and docker compose down -v delete volume data, such as databases and uploads. After docker compose down, that project’s volumes count as unused. Back up before removing volumes.

How to stop container logs filling the disk

By default the json-file log driver keeps logs without a size limit.
1

Set log rotation for all new containers

Create or edit /etc/docker/daemon.json:
This keeps at most three 10 MB log files per container.
2

Restart Docker

Running containers stop during the restart. Containers with a restart policy start again on their own.
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.
To empty one large log straight away without stopping the container:
Replace 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 with sudo crontab -e and add:
This runs every Sunday at 04:00 and never touches volumes. See schedule tasks with cron.

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 the du 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 and rm commands, or truncate for log files only.

Can I move Docker’s data to a bigger disk?

Yes, set data-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.

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:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026