Add Docker update functionality with configuration preservation to install-docker-ce.ps1
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:
- Stop Docker service
- Remove Docker service
- Backup
C:\ProgramData\docker\config\daemon.json - Run install script
- Stop Docker service again
- Restore daemon.json configuration
- 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:
# 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.jsonconfiguration - 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()andRestore-DockerConfig()with validation -
Enhanced Logic: Modified
Install-ContainerHost()andInstall-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 in the docs.
This issue has been open for 30 days with no updates. @ntrappe-msft, @Copilot, please provide an update or close this issue.
This issue has been open for 30 days with no updates. @ntrappe-msft, @Copilot, please provide an update or close this issue.
This issue has been open for 30 days with no updates. @ntrappe-msft, @Copilot, please provide an update or close this issue.
This issue has been open for 30 days with no updates. @ntrappe-msft, @Copilot, please provide an update or close this issue.
This issue has been open for 30 days with no updates. @ntrappe-msft, @Copilot, please provide an update or close this issue.
This issue has been open for 30 days with no updates. @ntrappe-msft, @Copilot, please provide an update or close this issue.