dokploy_orphaned_volumes_cleanup.sh - limehawk/rmm-scripts GitHub Wiki
dokploy_orphaned_volumes_cleanup.sh
Identifies and removes orphaned Docker volumes by scanning all containers and Docker Swarm services for volume usage.
Overview
Scans Docker containers and Swarm services to identify volumes that are not currently mounted or in use. Provides detailed information about orphaned volumes including size, creation date, and mount point. Can optionally remove orphaned volumes automatically to free up disk space.
Purpose
Scans Docker containers and Swarm services to identify volumes that are not currently mounted or in use. Provides detailed information about orphaned volumes including size, creation date, and mount point. Can optionally remove orphaned volumes automatically to free up disk space.
Prerequisites
- Docker installed and running
- Root/sudo access for volume inspection and removal
- Docker Swarm (optional, script works without it)
Configuration
Required Inputs
All configuration is hardcoded within the script.
AUTO_REMOVE - Set to true to automatically remove orphaned volumes, false for safe mode (list only)
- Default:
true - Type: Boolean
Behavior
- Scans all Docker containers (running and stopped) for volume mounts
- Scans all Docker Swarm services for volume usage
- Compares all system volumes against used volumes
- Displays detailed information for each orphaned volume
- Optionally removes orphaned volumes if AUTO_REMOVE is true
Security Notes
- No secrets exposed in output
- Requires privileged access to Docker daemon
- Volume data is permanently deleted when removed
Exit Codes
- 0 - Success
- 1 - Failure (error occurred)
Example Output
===================================
Dokploy Orphaned Volumes Finder
===================================
Step 1: Scanning containers for volume usage...
✓ Scanned 15 containers
Step 2: Scanning Docker Swarm services for volume usage...
✓ Scanned 3 Swarm services
Step 3: Getting all volumes on system...
✓ Found 20 total volumes
✓ Found 18 volumes in use
Step 4: Identifying orphaned volumes...
Found 2 orphaned volume(s):
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Volume: old_app_data
Created: 2024-10-15 14:23:45
Driver: local
Size: 2.3G
Path: /var/lib/docker/volumes/old_app_data/_data
Status: ⚠️ NOT USED by any container or service
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
===================================
Removing 2 orphaned volumes...
Done!
Version History
- v1.0.0 (2024-11-18) - Initial release with Limehawk Style A formatting
Links
- View Script Source
- Scripts - Back to script index