Skip to content

Docker on Windows (WSL 2)

Patrick Trumpis edited this page Mar 1, 2024 · 1 revision

Tips and Tricks

This guide provides tips on optimizing Docker's performance on Windows by adjusting WSL 2 settings.

Reducing RAM and CPU Usage

To manage Docker's resource consumption more effectively, you can configure WSL 2 to limit the amount of memory and CPU cores Docker can use.

Here’s how to do it:

  1. Create a Configuration File: Navigate to your user directory (%USERPROFILE%) and create a new file named .wslconfig.

  2. Edit the Configuration: Open the .wslconfig file in a text editor and include the following settings:

[wsl2]
memory=2GB # Limits WSL 2 to use up to 2GB of RAM
processors=2 # Limits WSL 2 to use up to 2 CPU cores
swap=2GB # Specifies the swap size

These settings restrict Docker to a maximum of 2GB of RAM and 2 CPU cores, but you can adjust the values based on your system's specifications.

  1. Apply the Changes: Save the .wslconfig file and restart WSL 2 for the changes to take effect.

You can restart WSL 2 by restarting your computer or by executing the command wsl --shutdown in the Windows Command Prompt or PowerShell, then reopening your WSL 2 terminal.

For more detailed information on configuring WSL 2, refer to the official Microsoft documentation.