Managing Memory and Processor Swap in WSL2 with Docker Desktop on Ubuntu

Abstract: Resolve WSL2 out-of-memory errors and CPU throttling during Docker Desktop operations by configuring memory and processor limits in the .wslconfig file.

Created: 2026-09-04 by
Optimizing WSL2 memory and processor allocation for Docker Desktop on Ubuntu requires editing the .wslconfig file in your Windows user directory. By default, WSL2 can consume excessive RAM and CPU resources, leading to system instability or performance degradation when running containerized workloads. Adjusting these limits ensures that Docker operations remain responsive without starving your host operating system of essential resources.

Understanding the Default Resource Limits

When you install Docker Desktop with WSL2 integration, it automatically provisions a virtual machine for your Linux distributions. By default, Microsoft sets aggressive resource ceilings to prevent WSL2 from impacting other Windows applications. Specifically, the hypervisor may allocate up to 50% of your total physical RAM and limit the number of processors used by the distribution. While this works for light tasks, heavy compilation jobs or multiple concurrent containers often hit these hard limits, causing Docker builds to fail with out-of-memory errors or significant latency.

If you are experiencing sluggish performance or unexpected crashes during intensive Docker operations, you likely need to tune these parameters. This is particularly relevant if you have ample hardware resources but find that WSL2 is not utilizing them efficiently. For more context on general troubleshooting within this environment, see Troubleshooting Docker on Ubuntu under WSL2 with Docker Desktop.

Locating and Creating the .wslconfig File

The configuration for WSL2 resources is managed through a plain text file named .wslconfig. This file must be placed in the root directory of your Windows user profile, typically located at C:\Users\\.wslconfig. If the file does not already exist, you can create it using any text editor such as Notepad or VS Code.

  1. Open File Explorer and navigate to C:\Users\.
  2. Select your user folder (e.g., C:\Users\JohnDoe).
  3. Create a new text file and rename it to .wslconfig. Ensure the extension is not hidden as .txt.
  4. Open the file with elevated privileges if necessary, though standard write access is usually sufficient.

It is crucial to ensure that the file has no trailing extensions like .txt, as WSL will ignore it if the name is incorrect. Once created, this file acts as the global configuration for all WSL2 instances on your machine.

Configuring Memory and Processor Limits

Inside .wslconfig, you define specific sections for memory and swap settings. The most common parameters to adjust are memory and processors. These settings apply globally to all WSL2 distributions unless overridden by distro-specific configurations.

[wsl2]
memory=8GB
processors=4
swap=4GB
localhostForwarding=true

In this example, we limit the WSL2 VM to use a maximum of 8 gigabytes of RAM and allow it to utilize 4 CPU cores. The swap parameter adds an additional 4 gigabytes of virtual memory space on the host disk, which helps prevent crashes when physical memory is exhausted. Setting localhostForwarding to true ensures that services running inside WSL2 are accessible via localhost on Windows, which is essential for Docker Desktop networking.

You should tailor these values based on your total system capacity. If you have 32GB of RAM, allocating 16GB to WSL2 might be appropriate for heavy development work. However, always leave enough headroom for Windows itself and other critical applications. For users migrating existing setups, understanding how these limits affect data persistence is key, as discussed in Importing Previously Exported WSL Distro.

Applying Changes and Verifying Configuration

WSL2 reads the .wslconfig file only during startup. Therefore, after saving your changes, you must fully shut down the WSL2 instance for the new settings to take effect. You cannot simply restart the service; you must terminate the entire virtual machine.

  • Open PowerShell or Command Prompt as Administrator.
  • Run the command wsl --shutdown. This forces all WSL2 distributions to stop completely.
  • Wait a few seconds, then start your Ubuntu distribution again via Docker Desktop or the terminal.

To verify that your new limits are active, open your Ubuntu terminal and run free -h to check available memory, or nproc to confirm the number of visible processors. Note that Docker Desktop may still impose its own internal limits on container resource usage, which are configured separately in the Docker Desktop UI under Settings > Resources. However, the .wslconfig settings act as the hard ceiling for the underlying WSL2 engine.

Troubleshooting Common Issues

If your changes do not seem to apply, check for syntax errors in the .wslconfig file. The file uses INI-style formatting, so incorrect indentation or missing brackets can cause WSL to ignore the entire file. Additionally, ensure that you are not conflicting with other configuration methods, such as using wsl.conf inside the Linux distribution, which handles different aspects of system configuration.

Some users report that Docker Desktop ignores .wslconfig settings because it manages its own WSL2 instance differently. In such cases, ensure that Docker Desktop is set to use the WSL2 backend correctly. If you encounter heap errors or memory corruption issues after adjusting these limits, refer to Ubuntu 20.04 on WSL2 with Windows 11 for deeper diagnostic steps related to memory management anomalies.

Frequently Asked Questions

Does changing .wslconfig affect all Linux distributions?

Yes, the .wslconfig file in your Windows user directory applies globally to all WSL2 distributions installed on that machine. If you need different limits for specific distros, you would need to configure them individually within their respective environments, though global limits still serve as a hard cap.

Why is my Docker build failing despite having enough RAM?

Docker builds might fail if the WSL2 memory limit is too low relative to the size of the image being built. Even if your host has plenty of RAM, WSL2 will throttle allocations once it hits the memory limit defined in .wslconfig. Increasing this value or enabling swap can resolve out-of-memory errors during compilation.

Can I set the memory limit to less than 1GB?

While technically possible, setting the memory limit below 1GB is not recommended for Docker Desktop. Most modern containerized applications require a minimum baseline of memory to initialize properly. Values this low will likely cause immediate crashes or severe performance degradation for basic operations.

How do I revert to default WSL2 settings?

To revert to defaults, simply delete the .wslconfig file from your Windows user directory or comment out all lines within it by adding a semicolon at the start of each line. After deleting or modifying the file, run wsl --shutdown to clear the current state and allow WSL2 to reload its default resource policies.

Is there a difference between wsl1 and wsl2 memory management?

Yes, .wslconfig primarily affects WSL2. WSL1 runs as a translation layer rather than a full virtual machine and does not use the same hypervisor-based memory allocation model. If you are still using WSL1, these settings will have no effect, and you should consider upgrading to WSL2 for better compatibility with Docker.

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