# Cleaning Up & Resource Limits — Docker Fundamentals: Images, Containers and Compose

Source: https://www.geekswithgeeks.com/en/docker/docker-cleanup-limits

> Reclaim disk space with docker system prune and cap container memory and CPU with run flags.

## Prune safely

Images, stopped containers and build cache pile up. `prune` removes unused ones.

```bash
docker system df            # see disk usage
docker container prune       # remove stopped containers
docker image prune -a        # remove unused images
docker system prune --volumes  # careful: also removes unused volumes
```

## Limit resources

Limits stop one container from starving the host.

```bash
docker run -d --name api --memory 512m --cpus 1.5 --restart unless-stopped my-app:1.0
```

`prune --volumes` can delete database data. Read the confirmation prompt, and prefer named volumes for anything you cannot afford to lose.
