docker desktop vmmem内存占用过高问题解决方案
内存占用过高原因
主要原因是docker desktop的实现及基于wsl(windows子系统),相当于在windows上同时开了一个虚拟机,如果不对wsl的资源进行限制,它将会极大的获取系统资源.所以我们只需要对wsl的最大资源进行限制即可
解决方案
修改wsl配置文件
具体配置:
# settings apply across all linux distros running on wsl 2 [wsl2] # limits vm memory to use no more than 4 gb, this can be set as whole numbers using gb or mb memory=4gb # sets the vm to use two virtual processors processors=2 # specify a custom linux kernel to use with your installed distros. the default kernel used can be found at https://github.com/microsoft/wsl2-linux-kernel kernel=c:\\temp\\mycustomkernel # sets additional kernel parameters, in this case enabling older linux base images such as centos 6 kernelcommandline = vsyscall=emulate # sets amount of swap storage space to 8gb, default is 25% of available ram swap=8gb # sets swapfile path location, default is %userprofile%\appdata\local\temp\swap.vhdx swapfile=c:\\temp\\wsl-swap.vhdx # disable page reporting so wsl retains all allocated memory claimed from windows and releases none back when free pagereporting=false # turn off default connection to bind wsl 2 localhost to windows localhost localhostforwarding=true # disables nested virtualization nestedvirtualization=false # turns on output console showing contents of dmesg when opening a wsl 2 distro for debugging debugconsole=true
在用户目录创建个.wslconfig文件,即c:\users\<username>\.wslconfig
创建完成后将配置文件内容粘贴进去
[wsl2] #配置wsl的核心数 processors=2 #配置wsl的内存最大值 memory=512mb #配置交换内存大小,默认是电脑内存的1/4 swap=8gb #关闭默认连接以将 wsl 2 本地主机绑定到 windows 本地主机 localhostforwarding=true #设置临时文件位置, 默认 %userprofile%\appdata\local\temp\swap.vhdx swapfile=d:\\temp\\wsl-swap.vhdx
保存后以管理员打开powershell,执行如下语句关闭wsl:
wsl --shutdown
重启docker desktop即可
后续问题(缺点)
如果内存设置的太小了,后续可能会出现docker desktop 运行一段时间退出,或者容器会突然停止工作
所以我们的memory=512mb
要根据自己启动的容器所占内存大小稍大一点即可,但是如果是后续需要增加容器需要自己手动再次扩大memory
到此这篇关于docker desktop vmmem内存占用过高问题解决方案的文章就介绍到这了,更多相关docker desktop vmmem内存占用过高内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论