Bil*_*rst 25

您是否正在运行 WSL 2 集成?在这种情况下,大部分设置似乎不适用,并且“高级”选项卡被删除。(参见https://admcpr.com/running-docker-desktop-with-the-new-wsl-2-backend/)。

  • @LizardDerad 我在常规选项卡“使用基于 WSL 2 的引擎”选项中禁用它,并且高级选项卡显示在资源下 (8认同)

小智 8

如果您使用新的 WSL 2 后端运行 docker desktop 并Use the WSL 2 based engine在 Settings/General 中启用: show settings/general

当您想修改 WSL 2 的配置设置以明确限制可用资源时,您可以通过在用户配置文件目录中创建 .wslconfig 文件来实现

打开 Windows Terminal/CMD/PowerShell 并运行以下命令:

# turn off all wsl instances such as docker-desktop
wsl -- shutdown

notepad "$env:USERPROFILE/.wslconfig"
Run Code Online (Sandbox Code Playgroud)

然后在 .wslconfig 文件中添加这些项目:

[wsl2]
kernel=<path>              # An absolute Windows path to a custom Linux kernel.
memory=<size>              # How much memory to assign to the WSL2 VM.
processors=<number>        # How many processors to assign to the WSL2 VM.
swap=<size>                # How much swap space to add to the WSL2 VM. 0 for no swap file.
swapFile=<path>            # An absolute Windows path to the swap vhd.
localhostForwarding=<bool> # Boolean specifying if ports bound to wildcard or localhost in the WSL2 VM should be connectable from the host via localhost:port (default true).

# <path> entries must be absolute Windows paths with escaped backslashes, for example C:\\Users\\adamc\\kernel
# <size> entries must be size followed by unit, for example 8GB or 512MB
Run Code Online (Sandbox Code Playgroud)

例如 :

[wsl2]
memory=2GB            
processors=4 
Run Code Online (Sandbox Code Playgroud)

然后保存文件并重新启动 docker-desktop 服务。