To fix this issue, you need (but firstly see Note #4 below):
- Back up the DockerDesktopVM virtual drive
- To find this path, open Hyper-V manager and Open setting of DockerDesktopVM, and find path. Usually it exists in vm-data folder in DockerDesktop ProgramData folder.
- Switch to Windows containers via tray icon
- Usually this file is locked. To unlock it, for me works, turning of all services with name Hyper-V and with name docker: Docker and Docker Desctop,HV Host Service,Hyper-V Host Compute Service,Hyper-V Virtual Machine Management,Docker Desktop Service. Also, Docker Desctop UI should be turned off via tray icon right click on it.
- Back up the file DockerDesktopVM !!!
- When the file DockerDesktopVM was back up, so all folder vm-data with this file maybe deleted (be aware and careful this file contains all your containers and images.)
- Starts all services back and run docker desktop UI.
- Switch back to Linux containers
- At this moment you will see the settings in DockerDesktop UI and new file was created in vm-data folder with name DockerDesktopVM
- Stop the all services again and replace the new file DockerDesktopVM with your old file which was backed up at the step 5.
- Start all services and Docker Desktop UI.
Note #1: most of difficulties ware with locked file DockerDesktopVM. Reboot is not required during manipulations with locked file. Updated: This file maybe acidentially attached as a disk to the host system. So, you need diskmgmt.msc on the host server. The disk was listed there, right click and choose detach. It prompts for confirmation that you have the correct file. At that point, process explorer confirms that the file is no longer open by pid 4 (nt kernel & system) and I am able to work freely with the .vhdx file. Updated 2: Or you need to run command net stop vmms
. Manipulate with file and start the vmms back with command net stop vmms
(origin https://community.spiceworks.com/topic/603713-solved-vhdx-can-t-be-deleted) Update 3: Anyway the vhdx file maybe locked due to VM is still running or hang. To determine this you can open vhdx file permission and see in the list of user one user with strange name similar to GUID - this is NT VIRTUAL MACHINE{GUID}. So, this is a virtual user under which your VM's process is running in windows. Then you can find the process vmwp.exe under this user in Taskmanager -> Details. Another way, you can find this process from Process Explorer latest version in Find Handler or DLL section by a search keyword 'vhdx'. You need to kill this process! After that, the vhdx file will be unlocked.
Note #2: If you backed up your DockerDesktopVM.vhdx file, so you can probably reset Docker to default for instance after step 7, or just reinstall the Docker Desktop
Note #3: Sometimes DockerDesktopVM.vhdx will be unlocked when it was deleted from Hyper-V Mager UI
Note #4: If your docker was able to start with wrong settings some how, but now it does not able to start. So, probably, you can try to avoid all manipulations above and just close all applications which consume a lot of memory, like chrome. And, try start docker again.
Note #5: Sometime, due to permissions, you can only delete file or copy it but can't rename.
But the core idea run Docker with fresh DockerDesktopVM file and replace it with the old one after when settings UI will be unlocked.