Production Docker · 8 min read · Intermediate
Resource Limits & Disk Cleanup (prune)
Cap container CPU/RAM limits so one runaway service never crashes your host, and reclaim disk space with docker system prune.
What you'll learn
- Cap container memory (--memory 256m) and CPU (--cpus 0.5) safely
- Inspect Docker disk usage with docker system df
- Clean dangling images and build cache safely without deleting active volumes
By default, a single container can consume 100% of your server’s RAM and CPU. Setting --memory 256m --cpus 0.5 protects neighboring services on small VPS droplets. Also monitor disk space periodically with docker system df and clear old unused layers with docker image prune -f.
Fill-in-the-Blank Exercise
Cap RAM & Clean Unused Images
Limit a container to 256m of RAM and inspect Docker disk usage.
docker run -d -- 256m --cpus 0.5 devpath-api:1.0
docker system Live Maintenance Script Lab
Bashdocker_maintenance.sh
Expected OutputClick “Run Live” to compile with GNU Bash
# Inspect space used by images, containers, and build cache docker system df # Reclaim space from unused images (preserves volumes!) docker image prune -af
Check Your Understanding
Score: 0 / 1
1. Why should you set --memory limits on containers running on a shared VPS?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.