- Problem Overview
- Diagnosis Steps
- Cleanup Procedures
- Prevention Strategies
- Automation Setup
- Monitoring
- Troubleshooting
- FAQs
Your VPS plan xxxxxxxxxx.hstgr.cloud
has almost reached its disk limit.
Please take immediate action to:
- Free up disk space by deleting unnecessary files.
- Upgrade your VPS plan to a higher storage capacity.
- Monitor your server usage to prevent service interruptions.
Disk space gradually increases with each Docker deployment due to:
- Dangling Docker Images: Untagged layers from previous builds (10-100MB+ each)
- Orphaned Containers: Stopped containers with lingering writable layers (5-50MB each)
- Unused Volumes: Persistent storage from old deployments (100MB-10GB+)
- Build Cache: Accumulated intermediate layers (500MB-5GB+)
- Unrotated Logs: Growing container log files (1MB-1GB+ per container)
Connect to your VPS account
# Overall disk usage
df -h
# Docker-specific usage
docker system df
- Sample output analysis:
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 15 3 8.5GB 7.2GB (84%) # 7.2GB can be cleaned!
Containers 10 2 500MB 500MB (100%)
Local Volumes 5 2 1.2GB 1.2GB (100%)
# All images (look for <none> tags)
docker images -a
# All containers (look for "Exited" status)
docker ps -a
# Dangling volumes
docker volume ls -f dangling=true
# Check log sizes
sudo du -sh /var/lib/docker/containers/*/*-json.log | sort -h
- Remove Stopped Containers
# Remove all stopped containers
docker container prune -f
# Remove specific container
docker rm [container_id]
- Clean Unused Images
# Remove dangling images only (safe)
docker image prune -f
# Remove ALL unused images (more aggressive)
docker image prune -a -f
# Remove images older than 24h
docker image prune -a -f --filter "until=24h"
- Clean Unused Volumes
# Remove all unused volumes
docker volume prune -f
# Remove specific volume
docker volume rm [volume_name]
- Additional Cleanup Options
# Build cache
docker builder prune -f
# Networks
docker network prune -f
# Complete system cleanup (careful!)
docker system prune -a -f --volumes
- Docker Daemon Configuration
/etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3",
"compress": "true"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
Apply changes:
sudo systemctl restart docker
- Deployment Best Practices
- Image Management:
# Use consistent tags
docker build -t myapp:latest .
# Multi-stage builds
FROM node:18 as builder
WORKDIR /app
COPY . .
RUN npm build
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
- Container Management:
# Auto-remove containers
docker run --rm myapp:latest
# Stop and remove old containers
docker stop old_container && docker rm old_container
- Cron Job for Regular Cleanup
# Edit crontab
crontab -e
# Add daily cleanup at 2AM
0 2 * * * /usr/bin/docker system prune -f --filter "until=24h"
- Post-Deployment Hooks In your deployment script:
#!/bin/bash
# Deployment commands...
docker-compose up -d --build
# Cleanup
docker image prune -f
docker builder prune -f
- Alternative Tools
- Docuum (LRU-based cleanup):
cargo install docuum
docuum --threshold 10GB
- docker-gc (Spotify's solution):
curl -L https://raw.githubusercontent.com/spotify/docker-gc/master/docker-gc > /usr/local/bin/docker-gc
chmod +x /usr/local/bin/docker-gc
docker-gc
# Quick status check
docker system df && df -h /var/lib/docker
# Set up alerts (example for Nagios)
command[check_docker_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /var/lib/docker
Problem: Cleanup doesn't free expected space Solution:
Check for mounted volumes: mount | grep docker
Verify storage driver: docker info | grep "Storage Driver"
Check for systemd mount leaks: systemctl list-units --type mount
Problem: Docker daemon won't start after config changes Solution:
sudo journalctl -u docker.service -n 50 --no-pager
sudo rm /etc/docker/daemon.json && systemctl restart docker
A: For active deployment servers, run cleanup daily. For development machines, run it weekly.
A: No, prune commands only remove unused resources. Running containers will not be affected.