Skip to content

Instantly share code, notes, and snippets.

@AndersHogqvist
Created May 20, 2024 13:42
Show Gist options
  • Select an option

  • Save AndersHogqvist/f4f63190731d133fc63e14387423f841 to your computer and use it in GitHub Desktop.

Select an option

Save AndersHogqvist/f4f63190731d133fc63e14387423f841 to your computer and use it in GitHub Desktop.
DockerSwitch - a ps1 script to switch between Linux and Windows containers
$ServiceDisplayName = "Docker Desktop Service"
# Stop all Docker processes
Stop-Process -Name *docker* -Force 2>$null
# Stop Docker Desktop Service and make sure it's stopped before continuing
$dockerService = Get-Service -DisplayName $ServiceDisplayName
while ($dockerService.Status -eq "Running") {
$dockerService = Get-Service -DisplayName $ServiceDisplayName
Start-Sleep -Seconds 1
}
# Parse settings.json
$settings = Get-Content "$env:APPDATA\Docker\settings.json" | ConvertFrom-Json
# Toggle useWindowsContainers
$settings.useWindowsContainers = -not $settings.useWindowsContainers
# Write the updated settings back to the file
$settings | ConvertTo-Json | Set-Content "$env:APPDATA\Docker\settings.json"
# Start Docker Desktop Service and wait until it's running
Start-Service -DisplayName "Docker Desktop Service"
while ($dockerService.Status -ne "Running") {
$dockerService = Get-Service -DisplayName $ServiceDisplayName
Start-Sleep -Seconds 1
}
# Start Docker Desktop
Start-Process "C:\Program Files\Docker\Docker\Docker Desktop.exe"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment