Reclaiming Hard Disk Space Used by Docker on Windows

Abstract: Reclaim disk space by stopping Docker, pruning artifacts, and compacting the WSL2 VHDX file.

Created: 2026-09-13 by
Docker on Windows consumes significant disk space through virtual hard disk (VHDX) files, container layers, and unused images. To reclaim this space, you must first stop the Docker Desktop service, then manually delete or compact the underlying WSL2 VHDX file located in your user profile. This process resolves storage bloat without requiring a full reinstallation of Docker or Hyper-V components.

Understanding Where Docker Stores Data

Docker Desktop for Windows relies on a lightweight Linux virtual machine running inside WSL2 (Windows Subsystem for Linux 2). The primary culprit for excessive disk usage is the ext4.vhdx file associated with the default WSL distribution used by Docker. Unlike standard files that shrink when data is deleted, VHDX files only grow; they do not automatically release freed space back to the host operating system.

Additionally, Docker maintains a local registry of images, containers, volumes, and build caches. Over time, stopped containers and dangling images accumulate, further contributing to storage consumption. While the Docker CLI can clean up these artifacts, it cannot reduce the size of the already allocated VHDX file. Therefore, a two-pronged approach is necessary: cleaning Docker artifacts and compacting the virtual disk.

Identifying the VHDX Location

The VHDX file is typically stored in the following path within your user directory:

%LOCALAPPDATA%\Docker\wsl\data\ext4.vhdx

If you are using a custom WSL distribution or have migrated your data, the location might vary slightly. You can verify the active WSL instance by opening PowerShell and running wsl -l -v. Look for the state of the docker-desktop and docker-desktop-data distributions. If these states show as Running, you must stop them before proceeding with any low-level disk operations.

Step-by-Step Cleanup Process

Follow these steps to safely reclaim disk space. Ensure you have backed up any critical data within your containers, as this process will remove all containerized data.

  1. Stop Docker Desktop: Right-click the Docker icon in the system tray and select "Quit Docker Desktop." Alternatively, use the task manager to end the Docker Desktop.exe process if it does not close normally.
  2. Shutdown WSL Instances: Open PowerShell as an administrator and run the following command to ensure no background processes are locking the VHDX file:
wsl --shutdown

This command forces all WSL2 instances to terminate immediately. Verify that the processes are gone by checking Task Manager or running wsl -l -v again; the status should be Stopped.

  1. Delete Old Artifacts via Docker: Before touching the VHDX, use Docker's built-in cleanup commands to remove unnecessary objects. Run:
docker system prune -a

This removes stopped containers, unused networks, dangling images, and build cache. Note that this operation deletes all images, so you may need to pull them again later. If you want to keep specific images, avoid the -a flag or manage them individually.

  1. Compact the VHDX File: Since deleting data inside the VM does not shrink the .vhdx file, you must compact it externally. First, navigate to the folder containing the VHDX file. Then, use the vhdutil tool or PowerShell cmdlets to compact the disk. For example, in PowerShell:
Optimize-VHD -Path "%LOCALAPPDATA%\Docker\wsl\data\ext4.vhdx" -Mode Full

This process may take several minutes depending on the size of the file. Once completed, check the file size; it should now reflect the actual used space rather than the maximum allocated capacity.

Preventing Future Bloat

To maintain optimal disk usage, consider configuring Docker to limit resource allocation. In Docker Desktop settings, under "Resources," you can set limits for CPU and memory, which indirectly helps manage the footprint of the WSL2 VM. Additionally, regularly running docker system prune as part of your maintenance routine prevents the accumulation of orphaned resources.

If you frequently work with large datasets or persistent volumes, consider mounting host directories directly into containers rather than storing data inside the container layer. This keeps the internal database lean and reduces the growth rate of the ext4.vhdx file. For more detailed guidance on managing WSL2 disk sizes, refer to our guide on optimizing WSL2 Docker VHDX file size.

Another common issue arises when Hyper-V features conflict with Docker's networking stack. Ensuring that Hyper-V is correctly enabled can prevent unexpected storage allocations due to failed virtual network adapters. Check our article on enabling Hyper-V for Docker Desktop to resolve related virtualization errors.

Frequently Asked Questions

Why doesn't Docker automatically shrink the VHDX file?

VHDX files are dynamic disks that expand as needed but do not contract automatically when data is deleted inside the guest OS. This behavior is inherent to how virtual hard disks handle sparse files and fragmentation. Manual compaction is required to return the freed space to the Windows host.

Is it safe to delete the ext4.vhdx file manually?

Deleting the file directly while Docker is running can corrupt your installation. You must ensure Docker Desktop is fully quit and WSL2 is shut down before removing or modifying the file. It is safer to compact the file rather than delete it entirely, unless you intend to reinstall Docker from scratch.

How can I check the current size of my Docker data?

You can use the command docker system df to view a summary of disk usage by images, containers, volumes, and build cache. For the total disk impact including the VHDX file, check the file size in %LOCALAPPDATA%\Docker\wsl\data\ using Windows Explorer or PowerShell.

Can I move the Docker data folder to another drive?

Yes, you can migrate the Docker data folder to another drive by changing the WSL2 configuration or symlinking the data directory. This requires stopping Docker, moving the data folder, and updating the symbolic link or configuration paths. This is useful if your C: drive has limited space.

What happens to my containers after pruning?

Pruning removes stopped containers and unused images. Any running containers remain unaffected until you explicitly stop them. However, if you use the -a flag with docker system prune, all images are removed, meaning you will need to pull them again to restart previous services.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More