Docker Desktop for Windows
, when installed using WSL 2 (Windows Subsystem for Linux 2)
as its backend, creates two distros or folders namely
docker-desktop-data under Windows Subsystem for Linux. That means if you go to
%LOCALAPPDATA%/Docker/wsl in File Explorer, you’d see two folders having
.vhdx files inside them as below:
data/ext4.vhdxthat is utilized by
distro/ext4.vhdxthat is utilized by
If you are having a limited amount of free storage space in the C drive aka the Windows system drive, then you’d want to avoid storing Docker’s distributions in there as their sizes will increase with time, which leads to congest the system drive, making it out of free storage space over time. And so, the solution is to move Docker’s data from the C drive to some other drive (say, D or E drive) in your system that has more storage space than the C drive. Let’s learn how you can do it:
The steps are pretty simple: we start with shutting down the Windows Subsystem for Linux, then exporting the distribution to an archive file, then unregistering the current distribution in WSL, and finally registering the same distribution from a different location using the archive file. Don’t forget to replace
D: with a drive you want to use in the code below.
1# Step 1 2wsl --shutdown 3 4# Step 2 5mkdir D:\Docker 6wsl --export docker-desktop D:\Docker\docker-desktop.tar 7 8# Step 3 9wsl --unregister docker-desktop 10 11# Step 4 12wsl --import docker-desktop D:\Docker\desktop D:\Docker\docker-desktop.tar --version 2 13del D:\Docker\docker-desktop.tar
The steps are mostly similar to the ones shown in the above section. You start by shutting down the WSL, exporting the Docker’s data distro to an archive file, deregistering the current Docker’s data distro with WSL, and re-registering the Docker’s data distro with WSL using the newly-created archive file in the last step. Simply run the code below:
1# Step 1 2wsl --shutdown 3 4# Step 2 5mkdir D:\Docker 6wsl --export docker-desktop-data D:\Docker\docker-desktop-data.tar 7 8# Step 3 9wsl --unregister docker-desktop-data 10 11# Step 4 12wsl --import docker-desktop-data D:\Docker\desktop-data D:\Docker\docker-desktop-data.tar --version 2 13del D:\Docker\docker-desktop-data.tar
I hope this post helped you migrate or move Docker from the system drive to any other drive on your system, which helps with managing or storing other apps and programs (as well as data) in the system drive. The reason being Docker requires a ton of storage space especially if you are downloading and running a lot of Docker distributions.
↫ Previous post
Get in touch to discuss an idea or project. We can work together to make it live! You can also enquire about writing guest posts or speaking in meetups or workshops.