0% found this document useful (0 votes)
270 views

How Can I Change The Location of Docker Images When Using Docker Desktop On WSL2 With Windows 10 Home - Stack Overflow

The document discusses how to change the location of Docker images when using Docker Desktop on Windows 10 Home with WSL2. It provides steps to relocate the default image location from the system disk (SSD) to a larger storage disk. The key steps include shutting down Docker Desktop, exporting the "docker-desktop-data" distribution, unregistering and re-importing it to the new location, and restarting Docker Desktop. This allows preserving existing images and containers while moving their storage to a higher capacity drive.

Uploaded by

John Jack
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
270 views

How Can I Change The Location of Docker Images When Using Docker Desktop On WSL2 With Windows 10 Home - Stack Overflow

The document discusses how to change the location of Docker images when using Docker Desktop on Windows 10 Home with WSL2. It provides steps to relocate the default image location from the system disk (SSD) to a larger storage disk. The key steps include shutting down Docker Desktop, exporting the "docker-desktop-data" distribution, unregistering and re-importing it to the new location, and restarting Docker Desktop. This allows preserving existing images and containers while moving their storage to a higher capacity drive.

Uploaded by

John Jack
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

How can I change the location of docker images when using Docker

Desktop on WSL2 with Windows 10 Home?


Asked 11 months ago Active today Viewed 24k times

I've just upgraded to Windows 10 Home May 2020, activated WSL2, and installed Docker
Desktop.
96
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.
39
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?

docker windows-10 docker-desktop wsl-2

Share Improve this question edited Feb 6 at 19:18 asked Jun 18 '20 at 2:21
Follow questionto42 neves
1,384 1 10 30 20.5k 15 108 137

8 Answers Active Oldest Votes

The WSL 2 docker-desktop-data vm disk image would normally reside in:


%USERPROFILE%\AppData\Local\Docker\wsl\data\ext4.vhdx
243
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
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose
You should
information be ablewith
in accordance to see,
our make
Cookiesure
Policythe
. STATE for both is Stopped.

NAME
Accept all cookies STATE
Customize settings VERSION
* docker-desktop Stopped 2
Join Stackdocker-desktop-data
Overflow to learn, share Stopped
knowledge, and build
2 your career. Sign up
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:

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

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

Share Improve this answer Follow edited Feb 20 at 10:40 answered Sep 5 '20 at 9:10
Franks CHOW
2,446 1 6 3

9 Perfect! I wanted to use my HDD instead of SSD for docker images. This was what I was looking for. – 
Wajahath Sep 14 '20 at 6:56

3 Clear and concise – Cyryl1972 Sep 23 '20 at 9:27

Perfect. The only add-on I can add to this thread, is that I had just purged my cache, and I didn't had
this docker-desktop-data present on listing, so I had to start Docker again and quit it in order to create
the docker-desktop-data WSL distro again. – Danton Heuer Oct 5 '20 at 4:43

4 Note that you will also need to shutdown wsl before exporting (I got a TimeoutException without that) :
wsl --shutdown . – Julian Didier Oct 19 '20 at 8:24

2 I suffered from low disk space for so long ... Thank you a lot ! – Disappointed Nov 9 '20 at 15:58

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.
10
You can do

Your privacy
wsl --unregister docker-desktop-data
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose
wslin--import
information accordancedocker-desktop-data
with our Cookie PolicyD:\wsl\docker-desktop-data
. "C:\Program
Files\Docker\Docker\resources\wsl\wsl-data.tar" --version=2

Accept all cookies Customize settings


The tar
Join Stack file is the
Overflow to file used
learn, to knowledge,
share install, and before it isyour
and build your new destination.
career. Sign up
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

Share Improve this answer Follow edited Nov 10 '20 at 18:05 answered Jul 22 '20 at 3:55
Yiming Lu
111 4

1. Stop Docker Desktop


2. Relocate Docker folder from C:\Users\xxx\AppData\Local\Docker to new path
8
3. Make sure C:\Users\xxx\AppData\Local\Docker is no longer there

4. Open a cmd in administrator mode

5. Run the following command that will create a symbolic link in the cmd window with the
appropriate from and to path

mklink /j "C:\Users\xxx\AppData\Local\Docker" "path to where you relocated your


docker folder"

6. Restart Docker Desktop

Share Improve this answer Follow edited Feb 22 at 19:45 answered Feb 22 at 17:39
dejdej Attila Badi
2,562 4 14 28 81 1 1

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
5 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:

1. Uninstall Docker. I know... Make sure you have saved what you need.

2. 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

3. 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"


Your privacy
mklink /j "C:\ProgramData\Docker" "D:\Data\Docker\AppData_Local_Docker"
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose
information in accordance with our Cookie Policy.
4. Install Docker.
Accept all cookies Customize settings
You should be able to merrily pull windows server images, but not clog up your boot drive.
Join Stack Overflow to learn, share knowledge, and build your career. Sign up
Share Improve this answer Follow answered Feb 23 at 20:24
Anthony Horne
2,324 2 25 49

1 I was trying to avoid this approach but looks like from all the ones I tried this one worked for me. I think
My problem is that I'm using new docker but in WSL1 setup and the 2021 answers do not apply on me.
And the locations were slightly different, I did only one link here: mklink /j
"C:\ProgramData\DockerDesktop" "D:\work\docker" – Anton Krug Apr 29 at 11:36

@AntonKrug I am running WSL 2 on an insider windows slow ring. – Anthony Horne Apr 29 at 12:48

1 I'm on WIN10 LTSC which so far has only the WSL1, so then docker put things into slightly different
folders and moving folders was not possible for me even when I shutdown Docker/Hyper-V. But when I
uninstalled, prepared the C:\ProgramData\DockerDesktop -> D drive link then just installed Docker
again then it did exactly what I wanted – Anton Krug Apr 29 at 13:48

1 Agreed. Shutdown did nothing for me either - it still runs WSL machines in the background somewhere.
Glad it worked for you. Docker should fix this and make it property part of settings (advanced even). – 
Anthony Horne Apr 30 at 10:29

1 It's ridiculous that it's not part of the regular install already, docker is not for casual consumers, yet
power users often have elaborate partions/hdds setups, so I would say Docker should have this as an
option for long time. Actually one of the reasons why I still use other frameworks like vagrant which feel
much more solidly build and designed. – Anton Krug Apr 30 at 10:40

I found this tool from pxlrbt on github. It's using standard wsl import/export and pretty safe.
Just moved both my docker-desktop-data distro to a different drive and it works well.
3
Share Improve this answer Follow answered Jun 20 '20 at 18:09
sidecus
581 3 9

1 After I moved using the above script, I got an error Docker desktop WSL distro stopped . Mind to
share the steps? – otong Aug 17 '20 at 17:07

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
0 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
Your you should delete the C:\Users\xxx\AppData\Local\Docker directory if it exists already else the
privacy
command
By clicking could
“Accept fail. Now
all cookies”, youinstall
agree docker desktopcan
Stack Exchange onstore
windows 10onhome
cookies and voila
your device and you can see
disclose
information in accordance with our Cookie Policy.
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.
Accept all cookies Customize settings
Join Stack Overflow to learn, share knowledge, and build your career. Sign up
Share Improve this answer Follow answered Jan 10 at 8:31
Anupam Yadav
3 3

For me docker won't start with junction.

0 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:

Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose
information in accordance with our Cookie Policy.

Accept all cookies Customize settings


Join Stack Overflow to learn, share knowledge, and build your career. Sign up
Share Improve this answer Follow answered May 15 at 12:35
RUben
101 3

A nice tool:
Your privacy
0By clicking
DDoSolitary/LxRunOffline:
“Accept all cookies”, youAagree
full-featured utilitycan
Stack Exchange forstore
managing
cookiesWindows Subsystem
on your device for Linux
and disclose
information
(WSL) in accordance with our Cookie Policy.

https://github.com/DDoSolitary/LxRunOffline
Accept all cookies Customize settings
Join Stack Overflow to learn, share knowledge, and build your career. Sign up
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

Share Improve this answer Follow answered 3 hours ago


Xingxing Qiao
116 5

Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose
information in accordance with our Cookie Policy.

Accept all cookies Customize settings


Join Stack Overflow to learn, share knowledge, and build your career. Sign up

You might also like