Reputation: 39143
I've just upgraded to Windows 10 Home May 2020, activated WSL2, and installed Docker Desktop.
WSL2 must be installed in my system disk, which is a small SSD. I don't want to fill it with docker images. How do I change the docker images path? I'd like to use a path in my big Windows filesystem.
The image location is somewhat confusing. I believe it is in /mnt/wsl/docker-desktop-data/
.
How do I change the directory of docker images inside WSL2? May I change docker configuration to select a path inside /mnt/d
, or mount a path from /mnt/d over docker data dirs?
Upvotes: 346
Views: 149304
Reputation: 3368
Docker for Windows now supports changing this in the UI as shown in the image below. I believe it handles moving the existing file as well.
Upvotes: 44
Reputation: 8266
The WSL 2 docker-desktop-data vm disk image would normally reside in:
%USERPROFILE%\AppData\Local\Docker\wsl\data\ext4.vhdx
Follow the following to relocate it to other drive/directory, with all existing docker data preserved (tested against Docker Desktop 2.3.0.4 (46911), and continued to work after updating the 3.1.0 (51484)):
First, shut down your docker desktop by right click on the Docker Desktop icon and select Quit Docker Desktop
Then, open your command prompt:
wsl --list -v
You should be able to see, make sure the STATE for both is Stopped.(wsl --shutdown
)
NAME STATE VERSION
* docker-desktop Stopped 2
docker-desktop-data Stopped 2
Export docker-desktop-data into a file
wsl --export docker-desktop-data "D:\Docker\wsl\data\docker-desktop-data.tar"
Unregister docker-desktop-data from wsl, note that after this, your ext4.vhdx
file would automatically be removed (so back it up first if you have important existing image/container):
wsl --unregister docker-desktop-data
Import the docker-desktop-data back to wsl, but now the ext4.vhdx would reside in different drive/directory (Note that you will need to create D:\Docker\wsl\data\
if it does not already exist):
wsl --import docker-desktop-data "D:\Docker\wsl\data" "D:\Docker\wsl\data\docker-desktop-data.tar" --version 2
Start the Docker Desktop again and it should work. In the event that Docker Desktop doesn't start correctly, restart the PC and try again.
You may delete the D:\Docker\wsl\data\docker-desktop-data.tar
file (NOT the ext4.vhdx
file) if everything looks good for you after verifying
Upvotes: 825
Reputation: 93
Just for reference for anyone finding this question, as of now (June 2023):
The export-import method fails on Windows for images larger than 8 GB. It's a bug in the underlying tar implementation.
Fortunately, there is a --vhd
switch for wsl that one can use for export and import. Even more, there is a wsl --import-in-place
command that is useful when one has large volumes.
Although moving the wsl .vhdx files to another location works from the wsl point of view, Docker Desktop still has problems with it. After it makes changes to "docker-data", e.g., the (smaller) distro\ext4.vhdx file, Docker Desktop finally deletes this volume and even a backup copy at the old (%APPDATA%\Docker\wsl\distro) location, and pops an error window.
All in all, I second the mklink
method on Windows as 1. it's the least hassle, 2. it's working.
Upvotes: 2
Reputation: 2522
Extending @Attila Badi 's answer would be to also give the same treatment to the C:\ProgramData\Docker folder, which seems to be used for WSL / Windows Containers. Even moving the Docker data folders, would still leave you with a boot drive ProgramData\Docker folder of massive proportions - especially if you are unable or unwilling to clean the images. You cannot migrate it, or move it once installed. Using the Docker engine advanced settings works in Linux container mode, but not in windows and vice versa and has trouble starting.
Steps I followed:
Uninstall Docker. I know... Make sure you have saved what you need.
Create the primary space-eating docker folders, in a location you have a lot of space, e.g. :
D:\Data\Docker\ProgramData_Docker
&
D:\Data\Docker\AppData_Local_Docker
Create linked folders, by running the below in a command window in administrator mode:
mklink /j "C:\Users\xxx\AppData\Local\Docker" "D:\Data\Docker\ProgramData_Docker"
mklink /j "C:\ProgramData\Docker" "D:\Data\Docker\AppData_Local_Docker"
You should be able to merrily pull windows server images, but not clog up your boot drive.
UPDATE:
Trying to symlink the C:\ProgramData\Docker folder, may result in a security error, depending on the version running depending on the originally installed version.
Release notes for 4.13.0 refers to this feature, which my be a possible work-around (Thanks to @bhagerty and @Oly for the trail):
start /w “” “Docker Desktop Installer.exe” install --installation-dir=G:\Docker
(Source: ungureanuovidiu @ https://forums.docker.com/t/docker-installation-directory/32773/17 )
Update:
This works on 4.17.1 BUT ProgramData_Docker changes to DockerDesktop. Broken Everything required a windows reset and reinstalling docker on windows 11 with the above changes still work / apply. NB remember the DocherDesktop change after one of the versions.
Upvotes: 13
Reputation: 143
The best option is to update the registry. Follow the below steps
wsl --shutdown
.wsl -d Ubuntu
.Upvotes: 5
Reputation: 23
Using small SSD also you may want to relocate WSL swap file location.
https://learn.microsoft.com/en-us/windows/wsl/wsl-config
Upvotes: 1
Reputation: 156
A nice tool:
DDoSolitary/LxRunOffline: A full-featured utility for managing Windows Subsystem for Linux (WSL)
https://github.com/DDoSolitary/LxRunOffline
LxRunOffline.exe move Move a distribution to a new directory.
Options:
-n arg Name of the distribution
-d arg The directory to move the distribution to.
for example:
quit docker desktop, then:
wsl --shutdown
LxRunOffline.exe move -n docker-desktop-data -d D:\vm\dockerdesktop\wsl\data
Upvotes: 5
Reputation: 201
For me docker won't start with junction.
Then I've used just directory symbolic link:
Docker stopped
Folder "wsl" moved to other location on disk "B"
RUben@AD-RUBEN C:\Users\RUben\AppData\Local\Docker
$ mklink /D wsl "B:\dev\wsl"
**symbolic link** created for wsl <<===>> B:\dev\wsl
Containers and Images are ready to use:
Upvotes: 10
Reputation: 721
C:\Users\xxx\AppData\Local\Docker
to new pathC:\Users\xxx\AppData\Local\Docker
is no longer there mklink /j "C:\Users\xxx\AppData\Local\Docker" "path to where you relocated your docker folder"
Upvotes: 72
Reputation: 23
In Windows 10 home, docker desktop creates the VM under ""C:\Users\xxx\AppData\Local\Docker" directory and it is this VM that contains the downloaded docker images. If you want to change the VM location from C: to a different directory you can do this by creating a junction on windows (prior to docker desktop installation) using a command like below:
mklink /j "C:\Users\xxx\AppData\Local\Docker" "D:\Users\xxx\AppData\Local\Docker"
Note that prior to executing the command the target directory structure should exist while you should delete the C:\Users\xxx\AppData\Local\Docker directory if it exists already else the command could fail. Now install docker desktop on windows 10 home and voila you can see stuff inside "D:\Users\xxx\AppData\Local\Docker" directory namely the docker VM hard disk image file that is going to contain all the downloaded docker images.
Upvotes: 2
Reputation: 411
Edit: re-register docker-desktop would set the default docker-data to C drive now, so we should only unregister docker-data as the accepted answer.
You can do
wsl --unregister docker-desktop-data
wsl --import docker-desktop-data D:\wsl\docker-desktop-data "C:\Program Files\Docker\Docker\resources\wsl\wsl-data.tar" --version=2
The tar file is the file used to install, and before it is your new destination.
This always work while the move-wsl
or lxrunoffline
didn't work for me on fast rings. And sometimes you have to unistall/install docker first
Upvotes: 24