Docker Desktop on Windows installs to your C: drive by default. When you pull large images (often 1.5GB each), add build layers, and stack containers, the ext4.vhdx file that holds all your container data bloats fast. This guide shows you how to route Docker to a secondary drive entirely, using CLI flags instead of the GUI.
Quick Start
Uninstall any existing Docker first. Then open PowerShell as admin and navigate to your Downloads folder where the installer is. Run:
1start /w "" "Docker Desktop Installer.exe" install --accept-license `
2 --installation-dir="D:\Containers\docker" `
3 --wsl-default-data-root="D:\Containers\wsl" `
4 --windows-containers-default-data-root="D:\Containers\windows-data"Replace D:\Containers with your target path. Wait for the installer to finish (it won’t show a progress window), then restart Windows.
Pre-Flight Checklist
Before you start, verify your environment.
Windows version (Build 19041+):
1[System.Environment]::OSVersion.VersionCheck Settings > System > About > Windows specifications to confirm.
WSL2 installed:
1wsl --list --verboseIf nothing shows, install WSL2 first: wsl --install. This installs Ubuntu by default.
Hyper-V enabled:
1Get-WindowsOptionalFeature -Online -FeatureName Hyper-VLook for State: Enabled. If it says Disabled, enable it:
1Enable-WindowsOptionalFeature -Online -FeatureName Hyper-V -AllThen restart.
Secondary drive with 80GB+ free space:
1Get-VolumeVerify your target drive (D:, E:, etc.) is listed and has at least 80GB free. SSD is strongly recommended—VHDX files are I/O-heavy.
Admin permissions: Run PowerShell as admin. You’ll see an error immediately if you lack permissions.
Recommended Directory Structure
On your secondary drive, create this layout:
1D:\Containers
2├───docker (Docker application binaries, ~1GB)
3├───wsl (WSL2 ext4.vhdx file, grows with images)
4└───windows-data (Windows container data, usually empty)Create these folders first:
1mkdir "D:\Containers\docker"
2mkdir "D:\Containers\wsl"
3mkdir "D:\Containers\windows-data"Understanding the Flags
The --installation-dir flag moves the Docker Desktop app binaries. These are small and don’t change often.
The --wsl-default-data-root flag is the important one. It moves the ext4.vhdx file, which holds all your Linux container data. This file grows with every image pull, layer, and container you create. It’s why your C: drive fills up. This is where the space gets consumed.
The --windows-containers-default-data-root flag moves the Windows container data root. You rarely need this unless you explicitly enable Windows container mode in Docker Desktop settings.
Installation Steps
Step 1: Uninstall Existing Docker (if present)
If Docker is already installed:
1# Stop the service
2sc.exe stop docker
3
4# Uninstall via Control Panel (or CLI)
5"C:\Program Files\Docker\Docker\uninstall.exe" --quietWait for the process to finish. You can verify removal:
1Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
2 Select-Object DisplayName |
3 grep DockerIf nothing shows, Docker is gone.
Step 2: Navigate to the Installer
Download Docker Desktop from here. You’ll get Docker Desktop Installer.exe. Move it to an easy location (e.g., C:\Users\YourUsername\Downloads) so the command below works.
Then, open PowerShell as admin and navigate to the folder:
1cd C:\Users\YourUsername\DownloadsStep 3: Run the Installer with Flags
1start /w "" "Docker Desktop Installer.exe" install --accept-license `
2 --installation-dir="D:\Containers\docker" `
3 --wsl-default-data-root="D:\Containers\wsl" `
4 --windows-containers-default-data-root="D:\Containers\windows-data"The start /w waits for the installer to finish. You won’t see a progress window, so the command will hang silently for 2-5 minutes depending on disk speed. This is normal and expected.
If it fails, skip to the Troubleshooting section below for solutions.
Step 4: Restart Windows
1Restart-ComputerThis is critical. Registry changes and WSL mount points won’t take effect until you restart.
Verification
After restart, verify the installation worked.
Run docker info to check the installation path:
1docker infoLook for Docker Root Dir. It should show your new path:
1Docker Root Dir: D:\Containers\wsl\docker-desktop-data\mnt\wsl\docker-desktop\cli-toolsTo filter just this line:
1docker info | select-string "Root Dir"Pull a test image to ensure the system works:
1docker pull nginx:latestCheck the file size of your WSL directory to confirm data is being stored there:
1(Get-ChildItem -Path "D:\Containers\wsl" -Recurse | Measure-Object -Property Length -Sum).Sum / 1GBYou should see a few GB now. On subsequent image pulls, this number grows.
Finally, verify that Docker isn’t secretly writing to C: anymore:
1Get-ChildItem "C:\Users\$env:USERNAME\AppData\Local\Docker" -ErrorAction SilentlyContinueThis folder may be empty now or contain only config files, not data.
Troubleshooting
Docker Desktop Won’t Start
If Docker Desktop icon appears in the system tray but immediately crashes or disappears, you likely have a permissions issue or registry mismatch. Open PowerShell as admin and stop any lingering process first:
1Get-Process -Name "Docker Desktop" -ErrorAction SilentlyContinue | Stop-Process -ForceThen delete the Docker Desktop config cache:
1Remove-Item "$env:APPDATA\Docker\*" -Recurse -Force -ErrorAction SilentlyContinueRestart Docker Desktop from the Start Menu. It should reinitialize cleanly.
“Path not found” or “Directory does not exist”
If the installer complains about your path, the directories probably don’t exist or there’s a typo. Verify the path exists first:
1Test-Path "D:\Containers\docker"Check that the drive letter is correct:
1Get-Volume -DriveLetter DIf the directories are missing, recreate them:
1mkdir "D:\Containers\docker"
2mkdir "D:\Containers\wsl"
3mkdir "D:\Containers\windows-data"Then re-run the installer.
“Access Denied” or Permission Errors
If the installer fails with a permission error even though you’re running as admin, Windows Defender or antivirus is locking files. Temporarily disable real-time scanning:
1Set-MpPreference -DisableRealtimeMonitoring $trueRe-run the installer, then re-enable scanning:
1Set-MpPreference -DisableRealtimeMonitoring $falseAlternatively, add your Docker path to Defender exclusions permanently:
1Add-MpPreference -ExclusionPath "D:\Containers"This prevents future scanning slowdowns.
“WSL 2 installation is incomplete” or WSL Errors
If Docker complains about WSL2 not being ready, the WSL2 kernel or distro is missing. Run these commands:
1wsl --install
2wsl --updateThen restart Windows.
Installation Succeeds but Docker Uses Old C: Drive Path
If docker info still shows C:\ProgramData\Docker, the registry settings weren’t applied or Docker has stale config. Uninstall completely first:
1wsl --unregister docker-desktop
2wsl --unregister docker-desktop-dataDelete the installation folder:
1Remove-Item "C:\Program Files\Docker" -Recurse -Force -ErrorAction SilentlyContinueThen reinstall using the CLI command from the Quick Start section.
“Docker daemon is not running”
If docker commands fail with a daemon not running error, the Docker Desktop service didn’t start. Manually start Docker Desktop from the Start Menu. Wait 10 seconds, then try a docker command:
1docker psIf it still fails, check the Docker Desktop logs:
1Get-Content "$env:APPDATA\Docker\log.txt" -Tail 50The last 50 lines usually show what’s preventing startup.
Performance Optimization
Once Docker is running from your secondary drive, a few adjustments improve performance.
Real-time scanning on the VHDX file during builds kills performance. Add the WSL directory to Windows Defender exclusions:
1Add-MpPreference -ExclusionPath "D:\Containers\wsl"Verify it was added:
1Get-MpPreference | Select-Object -ExpandProperty ExclusionPath | grep ContainersOpen Docker Desktop settings (right-click the icon, then Settings, then Resources) and adjust memory and CPU. Set “Memory” to 50-75% of your available RAM. Set “CPU” to 50% of your available cores. The disk image size auto-allocates to your secondary drive’s available space.
If images pull slowly, your secondary drive itself might be the bottleneck. Test its write speed:
1$testFile = "D:\Containers\speed-test.bin"
2$testSize = 100MB
3$buffer = new-object byte[] 1MB
4$file = [io.file]::Create($testFile)
5$sw = [diagnostics.stopwatch]::StartNew()
6for ($i = 0; $i -lt ($testSize / 1MB); $i++) {
7 $file.Write($buffer, 0, $buffer.Length)
8}
9$file.Close()
10$sw.Stop()
11$speed = ($testSize / 1MB) / $sw.ElapsedMilliseconds * 1000
12Write-Host "Write speed: $speed MB/s"
13Remove-Item $testFileIf you’re seeing below 50 MB/s, you either need an SSD or you have disk errors. HDDs are too slow for Docker’s VHDX workload.
FAQ
Can I move Docker after installation?
Yes. In Docker Desktop settings (right-click the icon, then Settings, then Resources, then Disk image location), you can change the data path. Docker will re-initialize the VHDX.
What if I only move the WSL data, not the application?
That’s fine. The --installation-dir flag is optional. If you only want to free space, use only --wsl-default-data-root.
Does this work with Docker Compose?
Yes. Docker Compose uses the same Docker daemon, so it inherits the new paths automatically.
Can I symlink the directory instead?
Not recommended. Windows VHDX files don’t play well with symlinks. The CLI flags are the proper way.
How do I migrate containers from C: to D:?
Export containers with docker export, or save images with docker save. Remove the old C: installation and reinstall to D:. When you restart, pull your images again.
Is this reversible?
Yes. Reinstall Docker to C: using the GUI installer or change the path back in Docker Desktop settings.
Why This Matters
Docker pulls large base images (Alpine 370MB, Ubuntu 1.3GB, Node 1.5GB, etc.) and layers them up. A real project easily accumulates 10-20GB. Add multiple projects, build caches, and temporary containers, and your C: drive fills in weeks.
When your C: drive fills, Windows degrades. It can’t write swap files, temp logs, or system caches. The whole machine gets slower. Moving Docker to a secondary drive is one of the highest-impact optimizations you can do as a developer because it’s both simple and immediately tangible.