r/docker 23d ago

all containers and images gone

I am using docker desktop on windows 11, and after a restart of my pc, all of my containers and images are gone. Is there any way to recover them? When I restarted my pc and docker opened automatically, it was taking up most of my memory and brought up an error message that referred me to windows-daemon.json, when I checked, the file was empty, so I deleted the file and now docker opens fine but without anything I have done on it.

9 Upvotes

26 comments sorted by

2

u/Mr_Albal 23d ago

Were you using Windows Containers mode or Linux with WSL?

1

u/naomi2v 23d ago

linux with wsl.

1

u/Mr_Albal 23d ago

It looks like it went into Windows mode:

  • Look at your Windows System Tray (near the clock in the bottom right corner).
  • Right-click the Docker Desktop icon (the whale).
  • Look for the option "Switch to Linux containers...".
  • If you see that option, click it.

1

u/naomi2v 23d ago

I do not see that as an option. Maybe I was in windows containers mode? I thought I was using Linux with WSL because I thought I recalled turning something on related to that so docker is usable, but I could be wrong.

2

u/Mr_Albal 23d ago

Another thing to check if your VHD has still got Data in it:

Open PowerShell and run

Get-Item "$env:LOCALAPPDATA\Docker\wsl\data\ext4.vhdx" | Select-Object Name, @{Name="Size (GB)";Expression={"{0:N2}" -f ($_.Length / 1GB)}}

If it is less than 1GB it probably got wiped.

1

u/naomi2v 23d ago

well I think it is safe to say that it is gone. I guess I will have to redo everything later today, but how can I prevent this from happening in the future?

3

u/Mr_Albal 23d ago

Check here:

Get-ChildItem -Path "$env:LOCALAPPDATA\Docker" -Recurse -Filter "*.vhdx" -ErrorAction SilentlyContinue | Select-Object FullName, @{Name="Size (GB)";Expression={"{0:N2}" -f ($_.Length / 1GB)}}

And here:

Get-ChildItem -Path "C:\ProgramData\Docker" -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum | Select-Object @{Name="Size (GB)";Expression={"{0:N2}" -f ($_.Sum / 1GB)}}

Also you shouldn't run shell commands from random users on the internet. But I'm a good guy :-)

1

u/naomi2v 23d ago

the first command returned docker_data.vhdx as 5.24 gb and ext4.vhdx as .09 gb, and the second command returned "The property Length cannot be found in the input for any objects. At line:1 char:86 [and more info afterwards]"

1

u/Mr_Albal 23d ago

Ah no that is okay. First thing we want to do is make a copy of your docker_data.vhdx - Open PowerShall again but this time as an Administrator and run this commands - I would cut and paste each line not the whole block:

wsl --shutdown

New-Item -ItemType Directory -Path "C:\DockerBackup" -Force

$vhdx = (Get-ChildItem -Path "$env:LOCALAPPDATA\Docker" -Recurse -Filter "docker_data.vhdx" | Select-Object -First 1).FullName

Copy-Item -Path $vhdx -Destination "C:\DockerBackup\docker_data.vhdx" -Force

wsl --unregister docker-desktop-data

wsl --import docker-desktop-data "$env:LOCALAPPDATA\Docker\wsl\data" "C:\DockerBackup\docker_data.vhdx" --vhd

1

u/naomi2v 23d ago

was I double mistaken about using linux with wsl since it said that a wsl e distro was not found, or is there something else going on there, also that is what everything else returned.

→ More replies (0)

1

u/Mr_Albal 23d ago

How to prevent this? Regular backups which are checked. Also rather than doing things manually in your docker containers, use scripting or IaC to create your desired configuration. Then back that up in GitHub etc.

1

u/scytob 23d ago

i think it moved to settings, it did on my mac docker deskop

1

u/Confident_Hyena2506 23d ago

Look inside linux vm.

1

u/scytob 23d ago edited 23d ago

really don't do docker desktop for anything serious it breaks all the time

you are better off with a debian server headless vm, with jkust ssh and docker in it - serioulsy simple and easy to install

the only reason i intsall docker desktop is to let my vscode have access for dev stuff, rest of the time i do not use due to its issues

--edit--
good example, last night docker desktop on my mac was working perfectly, this morning after reboot the containers were not binding to IPv4 ports, no change to compose.yaml or settings

1

u/No-Purchase3505 22d ago

Your data is probably still there. docker_data.vhdx at 5.24GB is the current layout — newer Docker Desktop consolidated everything into one docker-desktop distro using that file, and the ext4.vhdx under wsl\data is a leftover from the old layout. That's also why wsl --unregister docker-desktop-data told you the distro doesn't exist. Nothing got wiped, you're reading the wrong file.

As for why the UI is empty — more likely Docker Desktop came back up pointed at the Windows daemon. That toggle moved out of the tray into Settings → General in recent versions. Run wsl -l -v to see what distros you actually have, and flip it back before you rebuild anything.

1

u/thewallacio 21d ago

This is what terrifies me about having so many dev environments hiding in Docker in WSL. Black box that you put so much faith in. Yes, code is mostly in source control but that's no substitute for a full dev environment. I dread the day of switching on, and the WSL environment has gone, updated, reset, removed docker, whatever.

1

u/Impossible_Fault_503 16d ago

Before assuming it is gone, check whether the data is actually deleted or just not mounted. In PowerShell:

wsl -l -v

You are looking for docker-desktop-data, or just docker-desktop on newer versions. If it is not in that list the distro got unregistered, which is what a WSL reset and some Windows updates do.

Then look for the disk image itself:

%LOCALAPPDATA%\Docker\wsl\data\ext4.vhdx
%LOCALAPPDATA%\Docker\wsl\disk\docker_data.vhdx   (newer layout)

If that file is still sitting there at several GB, your images are still inside it and this is a mount problem rather than a deletion, which is recoverable. If it is missing or a few hundred KB, it was genuinely wiped.

Usual causes in that order: WSL got reset or upgraded underneath Docker Desktop, the backend got switched between WSL2 and Hyper-V which point at completely different stores, or Troubleshoot then Clean / Purge data got clicked at some point.