> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Free Disk Space with docker system prune

> Free Docker disk space: check use with docker system df, remove unused data with docker system prune, clear old images and cache, and rotate container logs.

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.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 10 minutes | Any Linux server with Docker Engine | Docker access (`docker` group or sudo) |

## 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"](https://help.freakhosting.com/portals/other/how-to-fix-no-space-left-on-device.md) first.

## How to see what Docker uses

```bash theme={null}
docker system df
```

```text theme={null}
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          12        3         6.8GB     5.1GB (75%)
Containers      5         3         120MB     40MB (33%)
Local Volumes   6         3         2.4GB     900MB (37%)
Build Cache     48        0         3.2GB     3.2GB
```

**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:

```bash theme={null}
sudo du -sh /var/lib/docker
sudo du -sh /var/lib/docker/containers/*/*-json.log | sort -h | tail -5
```

## What does each prune command remove?

| Command | Removes | Safe? |
| - | - | - |
| `docker container prune` | All stopped containers | Yes, if you don't need them |
| `docker image prune` | Dangling images (untagged layers left after updates) | Yes |
| `docker image prune -a` | Every image no container uses | Yes, but images are downloaded again when needed |
| `docker builder prune` | Unused build cache | Yes; the next build is slower |
| `docker network prune` | Networks no container uses | Yes |
| `docker volume prune` | Unused **anonymous** volumes | Check first |
| `docker volume prune -a` | **All** unused volumes, including named ones | Deletes data |
| `docker system prune` | Stopped containers, unused networks, dangling images, unused build cache | Yes |
| `docker system prune -a` | The same, plus all unused images | Yes |
| `docker system prune --volumes` | The same, plus unused anonymous volumes | Check first |

## How to clean up Docker safely

**1. Check what is running**

```bash theme={null}
docker ps -a
```

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

**2. Remove unused data**

```bash theme={null}
docker system prune -a
```

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

**3. Review volumes before deleting them**

```bash theme={null}
docker volume ls -f dangling=true
```

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

**4. Check the result**

```bash theme={null}
docker system df
df -h /
```

> [!WARNING]
>
> `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](https://help.freakhosting.com/portals/other/how-to-back-up-a-linux-server.md) 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`:

```json theme={null}
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}
```

This keeps at most three 10 MB log files per container.

**2. Restart Docker**

```bash theme={null}
sudo systemctl 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:

```bash theme={null}
sudo truncate -s 0 "$(docker inspect --format='{{.LogPath}}' web)"
```

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:

```bash theme={null}
0 4 * * 0 docker system prune -af --filter "until=168h" > /dev/null 2>&1
```

This runs every Sunday at 04:00 and never touches volumes. See [schedule tasks with cron](https://help.freakhosting.com/portals/other/how-to-schedule-tasks-with-cron.md).

## 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](https://help.freakhosting.com/portals/other/how-to-mount-a-new-disk-on-linux.md) and [manage VPS storage](https://help.freakhosting.com/portals/vps-panel/how-to-view-and-manage-vps-storage.md).

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Find what is using disk space](https://help.freakhosting.com/portals/other/how-to-find-what-is-using-disk-space-on-linux.md)
>
> Track down large folders.

> [card] [Fix No space left on device](https://help.freakhosting.com/portals/other/how-to-fix-no-space-left-on-device.md)
>
> When the disk is already full.

> [card] [Docker commands cheat sheet](https://help.freakhosting.com/portals/other/essential-docker-commands.md)
>
> Containers, images and volumes.

> [card] [Check disk space](https://help.freakhosting.com/portals/other/how-to-check-disk-space-on-linux.md)
>
> df and du explained.

***

> [!NOTE]
>
> **Checked against the official [Docker pruning documentation](https://docs.docker.com/engine/manage-resources/pruning/) and [json-file log driver docs](https://docs.docker.com/engine/logging/drivers/json-file/)** 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.

> [!NOTE]
>
> ### 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](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.