在Windows中移至WSL 2后向Docker容器分配内存 [英] Memory allocation to docker containers after moving to WSL 2 in Windows
问题描述
我最近更新了Docker环境,使其在Windows的 WSL 2
上运行。
I recently updated my Docker environment to run on WSL 2
on Windows.
用于设置内存分配限制在以前版本的容器中,我可以在Docker Desktop GUI中的 Settings-> Resources-> Advanced-> Preferences
下进行选择,以调整内存和CPU分配。
For setting memory allocation limits on containers in previous versions, I had option in Docker Desktop GUI under Settings->Resources->Advanced->Preferences
to adjust memory and CPU allocation.
在WSL 2集成之后,我找不到该选项。
After WSL 2 integration, I am not able to find that option.
我认为从现在开始我应该通过Linux发行版运行所有内容,所以这是我的解决方案能够找到:
I assume I should run everything through my Linux distro from now on, so this is the solution I was able to find:
docker run -d -p 8081:80 --memory="256m" container_name
我不想每次运行容器时都必须设置一个标志。有没有办法永久设置内存分配?
I dont want to have to set a flag each time when running a container. Is there a way to permanently set the memory allocation?
推荐答案
已删除内存和CPU设置以进行WSL2集成。但是,作为Windows 内部版本18945 的一部分,
The Memory and CPU settings are removed for WSL2 integration. However, as part of Windows Build 18945, there is a workaround to limit WSL2 memory usage.
Microsoft WSL团队介绍了一个名为 .wslconfig
的文件,用于调整WSL2设置。
Microsoft WSL team introduced a file called .wslconfig
for tweaking WSL2 settings.
基本上,您必须在%UserProfile%\.wslconfig
中创建该文件,然后在下面进行设置。
You basically have to create that file at %UserProfile%\.wslconfig
and set the settings below.
[wsl2]
memory=6GB # Any size you feel like
swap=0
localhostForwarding=true
重新启动计算机,从现在开始,高内存消耗不会有任何问题。
Restart your computer, and from now on, you won't have any problem with high memory consumption.
希望它会有所帮助!
这篇关于在Windows中移至WSL 2后向Docker容器分配内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!