Tranfer Docker Desktop to another drive

If you want to setup Docker Desktop and have your Ubuntu image you installed from the Microsoft Store off of your SSD and onto your HDD, here are some steps I put together and performed.

Disclaimer: This is an honest effort to transfer an image successfully. Always backup and do research before removing and deleting things.

First, uninstall Docker Desktop (back up etc..)
Second, remove the three main directories for \Docker\ and \DockerDesktop\

https://stackoverflow.com/questions/7331056/how-to-delete-a-folder-and-all-contents-using-a-bat-file-in-windows

del /s /q C:\Users\<username>\AppData\Local\Docker\*
rmdir /s /q C:\Users\<username>\AppData\Local\docker\

del /s /q C:\ProgramData\DockerDesktop\*
rmdir /s /q C:\ProgramData\DockerDesktop\

del /s /q C:\ProgramData\Docker\*
rmdir /s /q C:\ProgramData\Docker\

Third, Link these directories to your new location

https://stackoverflow.com/questions/62441307/how-can-i-change-the-location-of-docker-images-when-using-docker-desktop-on-wsl2

mklink /j "C:\Users\<username>\AppData\Local\Docker" "E:\wsl\docker\appdata_Docker"
mklink /j "C:\ProgramData\Docker" "E:\wsl\docker\programdata_Docker"
mklink /j "C:\ProgramData\DockerDesktop" "E:\wsl\docker\dockerDesktop"

4th, install docker desktop
feel free to check your logs : C:\Users\AppData\Local\Docker\

5th, install Ubuntu from the Microsoft Store

https://askubuntu.com/questions/759880/where-is-the-ubuntu-file-system-root-directory-in-windows-subsystem-for-linux-an
Install ubuntu and it puts it in some ugly location above.

6th, open powershell and lets stop wsl and confirm its stopped

wsl --shutdown
wsl --list -v

7th, lets back up our image, and go 2 extra steps to confirm no corruption before unregister your current image.

https://stackoverflow.com/questions/62441307/how-can-i-change-the-location-of-docker-images-when-using-docker-desktop-on-wsl2

wsl --export Ubuntu "E:\wsl\temp\ubuntu_backup.tar"


if you run into issues check these out:
https://github.com/microsoft/WSL/issues/4735
https://github.com/microsoft/WSL/blob/2cb110aba644d0bb3ff8d6445448d4e08e11df78/CONTRIBUTING.md#8-detailed-logs
https://blog.codonomics.com/2020/09/wsl-for-development-in-windows-10-is.html

8th, check number 1 for corruption on the export

double check with 7-zip that you can open archive (make sure its not corrupt)

9th, to go another step into making sure this works we will first import the backup to a new name instead of Ubuntu, and after we confirm its good we will delete the rest

wsl --import UbuntuNew "E:\wsl\docker\wsl\Ubuntu" "E:\wsl\temp\ubuntu_backup.tar" --version 2

10th, if you really want you can now unregister both images, and re-do for the ‘Ubunutu’ image name, but I am going to keep my UbunutuNew so I set it to my default

wsl --setdefault UbuntuNew
wsl --list

11th, hopefully you are now safe to un-register your image

wsl --unregister Ubuntu

12th, I think your safe to remove this, but I could be wrong.

C:\Users\<username>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_##########

13th, You can set your default username back to what you made it when you installed the Ubuntu image from the microsoft store
https://blog.codonomics.com/2020/09/wsl-for-development-in-windows-10-is.html

Function WSL-SetDefaultUser ($distro, $user) { Get-ItemProperty Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\*\ DistributionName | Where-Object -Property DistributionName -eq $distro | Set-ItemProperty -Name DefaultUid -Value ((wsl -d $distro -u $user -e id -u) | Out-String); };

WSL-SetDefaultUser UbuntuNew babylon

There you have it, all of your docker and your WSL image on your HDD instead of your SSD


Leave a Reply

Your email address will not be published.