Docker Desktop Vmmem內存占用過高問題及完美解決方案
Docker Desktop Vmmem內存占用過高問題解決方案
內存占用過高原因
主要原因是docker desktop的實現(xiàn)及基于wsl(Windows子系統(tǒng)),相當于在Windows上同時開了一個虛擬機,如果不對wsl的資源進行限制,它將會極大的獲取系統(tǒng)資源.所以我們只需要對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
在用戶目錄創(chuàng)建個.wslconfig文件,即C:\Users\<UserName>\.wslconfig
創(chuàng)建完成后將配置文件內容粘貼進去
[wsl2] #配置wsl的核心數(shù) 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,執(zhí)行如下語句關閉wsl:
wsl --shutdown
重啟docker desktop即可
后續(xù)問題(缺點)
如果內存設置的太小了,后續(xù)可能會出現(xiàn)docker desktop 運行一段時間退出,或者容器會突然停止工作
所以我們的memory=512MB
要根據(jù)自己啟動的容器所占內存大小稍大一點即可,但是如果是后續(xù)需要增加容器需要自己手動再次擴大memory
到此這篇關于Docker Desktop Vmmem內存占用過高問題解決方案的文章就介紹到這了,更多相關Docker Desktop Vmmem內存占用過高內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
如何在 Ubuntu 下通過 Docker 部署 Caddy 
本文介紹了如何在Ubuntu系統(tǒng)下通過Docker部署Caddy服務器,首先安裝Docker,然后啟動Docker服務并設置為開機自啟,接著拉取Caddy鏡像,并創(chuàng)建一個Caddyfile配置文件,使用命令運行Caddy容器,并將本地的Caddyfile掛載到容器內,感興趣的朋友跟隨小編一起看看吧2025-03-03