mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-03-02 10:20:46 +01:00
7.0 KiB
7.0 KiB
Docker Container Update/Upgrade Features
Overview
This implementation adds comprehensive Docker container update/upgrade functionality to CyberPanel with full data persistence using Docker volumes. The solution addresses the GitHub issue #1174 by providing safe container updates without data loss.
Features Implemented
1. Container Update with Data Preservation
- Function:
updateContainer() - Purpose: Update container to new image while preserving all data
- Data Safety: Uses Docker volumes to ensure no data loss
- Process:
- Extracts current container configuration (volumes, environment, ports)
- Pulls new image if not available locally
- Creates new container with same configuration but new image
- Preserves all volumes and data
- Removes old container only after successful new container startup
- Updates database records
2. Delete Container + Data
- Function:
deleteContainerWithData() - Purpose: Permanently delete container and all associated data
- Safety: Includes strong confirmation dialogs
- Process:
- Identifies all volumes associated with container
- Stops and removes container
- Deletes all associated Docker volumes
- Removes database records
- Provides confirmation of deleted volumes
3. Delete Container (Keep Data)
- Function:
deleteContainerKeepData() - Purpose: Delete container but preserve data in volumes
- Use Case: When you want to remove container but keep data for future use
- Process:
- Identifies volumes to preserve
- Stops and removes container
- Keeps all volumes intact
- Reports preserved volumes to user
Technical Implementation
Backend Changes
Views (views.py)
updateContainer()- Handles container updatesdeleteContainerWithData()- Handles destructive deletiondeleteContainerKeepData()- Handles data-preserving deletion
URLs (urls.py)
/docker/updateContainer- Update endpoint/docker/deleteContainerWithData- Delete with data endpoint/docker/deleteContainerKeepData- Delete keep data endpoint
Container Manager (container.py)
updateContainer()- Core update logic with volume preservationdeleteContainerWithData()- Complete data removaldeleteContainerKeepData()- Container removal with data preservation
Frontend Changes
Template (listContainers.html)
- New update button with sync icon
- Dropdown menu for delete options
- Update modal with image/tag selection
- Enhanced styling for new components
JavaScript (dockerManager.js)
showUpdateModal()- Opens update dialogperformUpdate()- Executes container updatedeleteContainerWithData()- Handles destructive deletiondeleteContainerKeepData()- Handles data-preserving deletion- Enhanced confirmation dialogs
User Interface
New Buttons
- Update Button (🔄) - Orange button for container updates
- Delete Dropdown (🗑️) - Red dropdown with two options:
- Delete Container (Keep Data) - Preserves volumes
- Delete Container + Data - Removes everything
Update Modal
- Container name (read-only)
- Current image (read-only)
- New image input field
- New tag input field
- Data safety information
- Confirmation buttons
Confirmation Dialogs
- Update: Confirms image/tag change with data preservation notice
- Delete + Data: Strong warning about permanent data loss
- Delete Keep Data: Confirms container removal with data preservation
Data Safety Features
Volume Management
- Automatic detection of container volumes
- Support for both named volumes and bind mounts
- Volume preservation during updates
- Volume cleanup during destructive deletion
Error Handling
- Rollback capability if update fails
- Comprehensive error messages
- Operation logging for debugging
- Graceful failure handling
Security
- ACL permission checks
- Container ownership verification
- Input validation
- Rate limiting (existing)
Usage Examples
Updating a Container
- Click the update button (🔄) next to any container
- Enter new image name (e.g.,
nginx,mysql) - Enter new tag (e.g.,
latest,1.21,alpine) - Click "Update Container"
- Confirm the operation
- Container updates with all data preserved
Deleting with Data Preservation
- Click the delete dropdown (🗑️) next to any container
- Select "Delete Container (Keep Data)"
- Confirm the operation
- Container is removed but data remains in volumes
Deleting Everything
- Click the delete dropdown (🗑️) next to any container
- Select "Delete Container + Data"
- Read the warning carefully
- Confirm the operation
- Container and all data are permanently removed
Benefits
For Users
- No Data Loss: Updates preserve all container data
- Easy Updates: Simple interface for container updates
- Flexible Deletion: Choose between data preservation or complete removal
- Clear Warnings: Understand exactly what each operation does
For Administrators
- Safe Operations: Built-in safety measures prevent accidental data loss
- Audit Trail: All operations are logged
- Rollback Capability: Failed updates can be rolled back
- Volume Management: Clear visibility into data storage
Technical Requirements
Docker Features Used
- Docker volumes for data persistence
- Container recreation with volume mounting
- Image pulling and management
- Volume cleanup and management
Dependencies
- Docker Python SDK
- Existing CyberPanel ACL system
- PNotify for user notifications
- Bootstrap for UI components
Testing
A test script is provided (test_docker_update.py) that verifies:
- All new methods are available
- Function signatures are correct
- Error handling is in place
- UI components are properly integrated
Future Enhancements
Potential Improvements
- Bulk Operations: Update/delete multiple containers
- Scheduled Updates: Automatic container updates
- Update History: Track container update history
- Volume Management UI: Direct volume management interface
- Backup Integration: Automatic backups before updates
Monitoring
- Update Notifications: Email notifications for updates
- Health Checks: Verify container health after updates
- Performance Metrics: Track update performance
- Error Reporting: Detailed error reporting and recovery
Conclusion
This implementation provides a complete solution for Docker container updates in CyberPanel while ensuring data safety through Docker volumes. The user-friendly interface makes container management accessible while the robust backend ensures data integrity and system stability.
The solution addresses the original GitHub issue by providing:
- ✅ Safe container updates without data loss
- ✅ Clear separation between container and data deletion
- ✅ User-friendly interface with proper confirmations
- ✅ Comprehensive error handling and rollback capability
- ✅ Full integration with existing CyberPanel architecture