Lesson 14 / 28
Cleaning Up & Resource 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.
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 volumesLimit resources
Limits stop one container from starving the host.
docker run -d --name api --memory 512m --cpus 1.5 --restart unless-stopped my-app:1.0prune --volumes can delete database data. Read the confirmation prompt, and prefer named volumes for anything you cannot afford to lose.