On Windows 10, what is the proper way to install docker on another drive (not C:\)?

I installed using the started the “Docker Desktop Installer.exe” from docker.com.
I downloaded a linux debian container.

Then I tried the getting started tutorial from docker.com and it was working until I had to access the file “DockerFile” which I realized would need to be on my working drive.

So I decided to reinstall docker to another drive but I remembered that the application does not ask for a drive, it simply installs directly on the C: drive without asking. That is causing many people to waste time on Windows I think. Like many people, my C: drive is a smaller SSD drive so I don’t want to use it for docker.

So I tried to change the default drive for docker/container/files/data but I did not see any options in the GUI.

So I searched the doc/forums and I found some solutions but none of them worked so far.

Solution 1:
I saw some people trying to move the dockers using these commands so I tried it:
wsl --export docker-desktop-data d:\docker-desktop-data.tar
wsl --unregister docker-desktop-data
wsl --import docker-desktop-data d:\Dockers\ d:\docker-desktop-data.tar --version 2
I did not get any error so it seemed to work. I can see a file:
d:\Dockers\ext4.vhdx (740MB)
But after restarting DockerDesktop, it did not see my previous ‘getting started’ docker I had installed. So I guessed there was something missing.

Solution 2:
I tried the following which I found on StackOverflow and on Microsoft documentation:
Create a file “C:\ProgramData\Docker\config\deamon.json” with this in it:

{
“data-root”: “D:\\Dockers”
}

But after restarting DockerDesktop, it did not see my previous ‘getting started’ docker either.

Solution 3:
Using DockerDesktop, tried adding this line in the json under “Settings → Docker Engine”:

,"data-root": "D:\\Dockers"

At this point, when I launch DockerDesktop, it justs show “docker desktop starting…” and seems to be stuck there. After a few minutes, a popup error message appears:

System.TimeoutException:
Timed out while wait for Docker service to be ready. Engine state: starting. Current action: waiting for Docker API to respond on unix:///var/run/docker.sock
at Docker.Engines.LinuxkitDaemonStartup.d__5.MoveNext() in C:\workspaces\PR-17132\src\githubcom\docker\pinata\win\src\Docker.Engines\LinuxkitDaemonStartup.cs:line 77
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Docker.Engines.WSL2.LinuxWSL2Engine.d__28.MoveNext() in C:\workspaces\PR-17132\src\githubcom\docker\pinata\win\src\Docker.Engines\WSL2\LinuxWSL2Engine.cs:line 179
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Docker.ApiServices.StateMachines.TaskExtensions.d__0.MoveNext() in C:\workspaces\PR-17132\src\githubcom\docker\pinata\win\src\Docker.ApiServices\StateMachines\TaskExtensions.cs:line 29
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Docker.ApiServices.StateMachines.StartTransition.d__5.MoveNext() in C:\workspaces\PR-17132\src\githubcom\docker\pinata\win\src\Docker.ApiServices\StateMachines\StartTransition.cs:line 67
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Docker.ApiServices.StateMachines.StartTransition.d__5.MoveNext() in C:\workspaces\PR-17132\src\githubcom\docker\pinata\win\src\Docker.ApiServices\StateMachines\StartTransition.cs:line 92

I am not sure what to do next. Is there an easy way to install Docker so I can choose which drives/folders it will use?

The preferred method for configuring the Docker Engine on Windows is using a configuration file. The configuration file can be found at 'C:\ProgramData\Docker\config\daemon.json'. You can create this file if it doesn't already exist.
....
Likewise, the following sample configures the Docker daemon to keep images and containers in an alternate path. If not specified, the default is c:\programdata\docker.
{   
    "data-root": "d:\\docker"
}

Thanks but as I said in my original post under ‘Solution 2’, it did not work for me. My original post did not show it so I just updated it to clarify that I did put the extra ‘slash’ for the folder.
Perhaps there is something else I need to do before/after that?

You can move docker-desktop-data to the drive of your choice after installation and after first run.
Important: do not move docker-desktop only move docker-desktop-data
Before you start stop any running containers and exit docker-desktop

Open powershell type

wsl -l

you should see in the list

docker-desktop-data

Now type

wsl --shutdown
wsl -l -v

You should now see everything is stopped.

Next we export a tar file to the drive of your choice in this case I’m using the root of d:\
You can use any directory you want

wsl --export docker-desktop-data d:\docker-desktop-data.tar

This can take a while depending on how much data is in there.

Now we need to unregister the folder and verify it is indeed unregistered

wsl --unregister docker-desktop-data
wsl -l

docker-desktop-data should no longer be on the list

To finish the move

wsl --import docker-desktop-data d:\docker-desktop-data d:\docker-desktop-data.tar
wsl -l

Again it may take a while but should see docker-desktop-data listed again

Lastly open the docker-desktop app and run anything as a test

docker run hello-world

I hope I didn’t miss any steps.

2 Likes

It seems like we need to run

wsl --import docker-desktop-data D:\docker-desktop-data D:\docker-desktop-data.tar --version 2

since the recent Docker does not support WSL version 1.
Without specifying --version 2, it imports the data as WSL version 1.