Docker初始化失败(提示WSL仍占用文件句柄)求助
兄弟我之前碰到过完全一样的问题!你这个情况核心就是WSL相关进程没彻底关闭,还在占用Docker的虚拟磁盘文件,导致Docker没法清理或初始化目标目录。先给你理清楚报错里的关键点:
An unexpected error was encountered while preparing a WSL distro destination directory.
The most likely cause for this is WSL still holding onto handles for the contents of the directory in question. So shut it down (wsl --shutdown), or reboot your machine. If the issue persists please collect diagnostics and submit an issueError details:
2 errors occurred:
- provisioning docker WSL distros: deploying "docker-desktop-data": preparing directory for WSL distro dir="C:\Users\Vlado\DockerDesktopWSL" distro="docker-desktop-data": removing distro destination dir "C:\Users\Vlado\DockerDesktopWSL": remove C:\Users\Vlado\DockerDesktopWSL\main\ext4.vhdx: The process cannot access the file because it is being used by another process.
- checking if isocache exists: CreateFile \wsl$\docker-desktop-data\isocache: The network name cannot be found.
下面是亲测有效的解决步骤,按顺序来:
第一步:彻底关闭WSL。打开管理员权限的PowerShell或CMD,运行命令:
wsl --shutdown
等个5-10秒,让系统把所有WSL相关的进程都停掉。第二步:手动清理残留进程。打开任务管理器,切换到“详细信息”标签,找有没有
wsl.exe、docker-desktop.exe、docker-desktop-data这类进程,找到就右键“结束任务”,确保全部干掉。第三步:重新启动Docker Desktop。这时候再打开Docker,一般就能正常初始化了。如果还是不行,那就直接重启电脑——重启是万能的,能彻底释放所有被占用的文件句柄。
极端情况:如果上面的方法都没用,可以试试重置Docker的WSL分发。打开Docker Desktop的设置,找到「Resources」->「WSL Integration」,点击「Reset to factory defaults」(注意:这个操作会清除你本地的Docker镜像和容器数据,谨慎使用!)
备注:内容来源于stack exchange,提问作者Čamo




