# How to Install Docker Desktop on Another Drive in Windows

> **Source:** [http://localhost:1313/docker-custom-installation-location-windows/](http://localhost:1313/docker-custom-installation-location-windows/)
> **Author:** [Vikash Patel](https://vikashpatel.net)
> **Published:** January 27, 2024
> **Reading Time:** 8 min
> 
> *This is the raw Markdown source of the article from the [Lorbic Technical Journal](http://localhost:1313/).*

---


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:

```powershell
start /w "" "Docker Desktop Installer.exe" install --accept-license `
  --installation-dir="D:\Containers\docker" `
  --wsl-default-data-root="D:\Containers\wsl" `
  --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+):**
```powershell
[System.Environment]::OSVersion.Version
```
Check `Settings > System > About > Windows specifications` to confirm.

**WSL2 installed:**
```powershell
wsl --list --verbose
```
If nothing shows, install WSL2 first: `wsl --install`. This installs Ubuntu by default.

**Hyper-V enabled:**
```powershell
Get-WindowsOptionalFeature -Online -FeatureName Hyper-V
```
Look for `State: Enabled`. If it says `Disabled`, enable it:
```powershell
Enable-WindowsOptionalFeature -Online -FeatureName Hyper-V -All
```
Then restart.

**Secondary drive with 80GB+ free space:**
```powershell
Get-Volume
```
Verify 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:

```text
D:\Containers
├───docker          (Docker application binaries, ~1GB)
├───wsl              (WSL2 ext4.vhdx file, grows with images)
└───windows-data     (Windows container data, usually empty)
```

Create these folders first:

```powershell
mkdir "D:\Containers\docker"
mkdir "D:\Containers\wsl"
mkdir "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:

```powershell
# Stop the service
sc.exe stop docker

# Uninstall via Control Panel (or CLI)
"C:\Program Files\Docker\Docker\uninstall.exe" --quiet
```

Wait for the process to finish. You can verify removal:
```powershell
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | 
  Select-Object DisplayName | 
  grep Docker
```

If nothing shows, Docker is gone.

### Step 2: Navigate to the Installer

Download Docker Desktop from [here](https://docs.docker.com/desktop/install/windows-install/). 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:
```powershell
cd C:\Users\YourUsername\Downloads
```

### Step 3: Run the Installer with Flags

```powershell
start /w "" "Docker Desktop Installer.exe" install --accept-license `
  --installation-dir="D:\Containers\docker" `
  --wsl-default-data-root="D:\Containers\wsl" `
  --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

```powershell
Restart-Computer
```

This 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:

```powershell
docker info
```

Look for `Docker Root Dir`. It should show your new path:

```
Docker Root Dir: D:\Containers\wsl\docker-desktop-data\mnt\wsl\docker-desktop\cli-tools
```

To filter just this line:

```powershell
docker info | select-string "Root Dir"
```

Pull a test image to ensure the system works:

```powershell
docker pull nginx:latest
```

Check the file size of your WSL directory to confirm data is being stored there:

```powershell
(Get-ChildItem -Path "D:\Containers\wsl" -Recurse | Measure-Object -Property Length -Sum).Sum / 1GB
```

You should see a few GB now. On subsequent image pulls, this number grows.

Finally, verify that Docker isn't secretly writing to C: anymore:

```powershell
Get-ChildItem "C:\Users\$env:USERNAME\AppData\Local\Docker" -ErrorAction SilentlyContinue
```

This 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:

```powershell
Get-Process -Name "Docker Desktop" -ErrorAction SilentlyContinue | Stop-Process -Force
```

Then delete the Docker Desktop config cache:

```powershell
Remove-Item "$env:APPDATA\Docker\*" -Recurse -Force -ErrorAction SilentlyContinue
```

Restart 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:

```powershell
Test-Path "D:\Containers\docker"
```

Check that the drive letter is correct:

```powershell
Get-Volume -DriveLetter D
```

If the directories are missing, recreate them:

```powershell
mkdir "D:\Containers\docker"
mkdir "D:\Containers\wsl"
mkdir "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:

```powershell
Set-MpPreference -DisableRealtimeMonitoring $true
```

Re-run the installer, then re-enable scanning:

```powershell
Set-MpPreference -DisableRealtimeMonitoring $false
```

Alternatively, add your Docker path to Defender exclusions permanently:

```powershell
Add-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:

```powershell
wsl --install
wsl --update
```

Then 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:

```powershell
wsl --unregister docker-desktop
wsl --unregister docker-desktop-data
```

Delete the installation folder:

```powershell
Remove-Item "C:\Program Files\Docker" -Recurse -Force -ErrorAction SilentlyContinue
```

Then 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:

```powershell
docker ps
```

If it still fails, check the Docker Desktop logs:

```powershell
Get-Content "$env:APPDATA\Docker\log.txt" -Tail 50
```

The 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:

```powershell
Add-MpPreference -ExclusionPath "D:\Containers\wsl"
```

Verify it was added:

```powershell
Get-MpPreference | Select-Object -ExpandProperty ExclusionPath | grep Containers
```

Open 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:

```powershell
$testFile = "D:\Containers\speed-test.bin"
$testSize = 100MB
$buffer = new-object byte[] 1MB
$file = [io.file]::Create($testFile)
$sw = [diagnostics.stopwatch]::StartNew()
for ($i = 0; $i -lt ($testSize / 1MB); $i++) {
  $file.Write($buffer, 0, $buffer.Length)
}
$file.Close()
$sw.Stop()
$speed = ($testSize / 1MB) / $sw.ElapsedMilliseconds * 1000
Write-Host "Write speed: $speed MB/s"
Remove-Item $testFile
```

If 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.

{{< newsletter >}}

