Overview
Lightd supports OS-level disk quotas for volumes to prevent containers from consuming unlimited disk space. Quotas are enforced at the filesystem level using platform-specific mechanisms.Features
OS-Level Enforcement
Uses native OS mechanisms (disk images on macOS, loop devices on Linux)
Default 1GB Quota
Volumes default to 1GB if no size specified
Customizable Size
Specify size in MB during creation
Real-time Monitoring
Check quota usage at any time
Resizable
Expand or shrink volume quotas
WebSocket Alerts
Get notified when volume is out of space
Platform Support
- macOS
- Linux
- Other Platforms
- Uses sparse disk images (
.sparseimage) - Mounted via
hdiutil - Supports dynamic resizing
- Efficient space usage (sparse allocation)
Create Volume with Quota
Create a new volume with specified disk quota.size(optional) - Disk quota in MB (default: 1024 = 1GB)
{"size": 1024}= 1GB{"size": 2048}= 2GB{"size": 10240}= 10GB{}or no body = 1GB default
Get Quota Usage
Check current disk usage for a volume.size_mb- Total quota size in MBused_mb- Currently used space in MBavailable_mb- Available space in MBpercentage_used- Percentage of quota used (0-100)
Resize Volume
Change the disk quota for an existing volume.size(required) - New quota size in MB
WebSocket Notifications
When a container’s volume runs out of space, Lightd sends a WebSocket event:Quota Monitoring
Lightd automatically monitors volume quotas and considers a volume “out of space” when:- Less than 10MB available, OR
- More than 95% of quota used
Applications should monitor quota usage and handle low disk space appropriately.
Size Reference
Common size conversions:| Size | MB Value | JSON Example |
|---|---|---|
| 512MB | 512 | {"size": 512} |
| 1GB | 1024 | {"size": 1024} |
| 2GB | 2048 | {"size": 2048} |
| 5GB | 5120 | {"size": 5120} |
| 10GB | 10240 | {"size": 10240} |
| 20GB | 20480 | {"size": 20480} |
| 50GB | 51200 | {"size": 51200} |
| 100GB | 102400 | {"size": 102400} |
MB = GB × 1024
Complete Example
Here’s a complete workflow for managing volume quotas:Best Practices
Set Appropriate Quotas
Set Appropriate Quotas
Estimate application needs and add buffer space. Better to start larger than to resize frequently.
Monitor Usage
Monitor Usage
Regularly check quota usage via API. Set up alerts when usage exceeds 80%.
Handle Disk Full
Handle Disk Full
Implement error handling for disk full scenarios. Listen to WebSocket events for storage alerts.
Plan for Growth
Plan for Growth
Resize volumes before hitting limits. Don’t wait until 95% full.
Use WebSocket Events
Use WebSocket Events
Subscribe to storage alerts to get real-time notifications when volumes are running low.
Technical Implementation
- macOS
- Linux
Limitations
- macOS: Requires
hdiutil(included in macOS) - Linux: Requires
mount,mkfs.ext4,resize2fs(usually pre-installed) - Permissions: May require elevated permissions for mount operations
- Performance: Slight overhead compared to direct filesystem access
- Resize Downtime: Volume temporarily unavailable during resize
Error Handling
Failed to create disk image
Failed to create disk image
Causes:
- Insufficient disk space on host
- Permission issues
- Missing system tools
- Check available disk space
- Verify permissions
- Ensure
hdiutil(macOS) ormount(Linux) is available
Failed to mount
Failed to mount
Causes:
- Mount point already in use
- Disk image/file doesn’t exist
- System mount limits reached
- Check if mount point is in use
- Verify disk image/file exists
- Check system mount limits
Resize failed
Resize failed
Causes:
- Cannot shrink below current usage
- Invalid new size
- Insufficient host disk space
- Ensure new size is larger than current usage
- Verify new size is valid
- Check available host disk space
Security Considerations
- DoS Prevention: Quotas prevent disk exhaustion attacks
- Isolation: Each volume is isolated from others
- Host Protection: Host filesystem protected from container abuse
- OS-Level Enforcement: Quota enforcement at OS level (cannot be bypassed)