ITADN

Add Docker update functionality with configuration preservation to install-docker-ce.ps1

#599Pull RequestCopilot 创建于 2025-06-02
C
Copilotcommented
This PR enhances the `install-docker-ce.ps1` script to support updating existing Docker installations while preserving the `daemon.json` configuration file, eliminating the need for manual backup/restore steps. ## Problem Previously, updating Docker required a complex 7-step manual process: 1. Stop Docker service 2. Remove Docker service 3. Backup `C:\ProgramData\docker\config\daemon.json` 4. Run install script 5. Stop Docker service again 6. Restore daemon.json configuration 7. Start Docker service The script would either skip installation entirely if Docker was already installed, or perform a clean install that overwrote existing configuration. ## Solution Added a new `-Update` switch parameter that automates the entire update process: ```powershell # Update existing Docker installation while preserving config .\install-docker-ce.ps1 -Update # Update with specific version .\install-docker-ce.ps1 -Update -DockerVersion "20.10.17" ``` ## Key Features **Automated Update Process:** - Validates and backs up existing `daemon.json` configuration - Gracefully stops and unregisters Docker service - Installs new Docker binaries - Registers service with preserved configuration - Handles cleanup automatically **Robust Error Handling:** - Validates JSON content before backup - Graceful handling of service operation failures - Automatic config restoration if update fails - Comprehensive error messages and warnings **Backwards Compatibility:** - All existing functionality preserved unchanged - New parameter is optional with no impact on existing scripts - Default behavior remains identical ## Technical Implementation - **New Functions:** `Backup-DockerConfig()` and `Restore-DockerConfig()` with validation - **Enhanced Logic:** Modified `Install-ContainerHost()` and `Install-Docker()` to handle update scenarios - **Error Recovery:** Automatic restoration of configuration if update fails partway through ## Testing The implementation includes comprehensive error handling for edge cases: - Missing or corrupted daemon.json files - Permission issues during backup/restore operations - Docker service operation failures - Failed updates with automatic recovery Fixes #595. --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.
合并状态:未合并 7 条评论