84

This is not a duplicate of Change Docker machine location - Windows

I'm using docker native, version 1.12.1-stable (build: 7135) on Windows 10 Pro with Hyper-V enabled. So docker is not running with VirtualBox nor do I have the folder C:\Users\username\.docker

I'd like to move docker's images, caches, ... to my secondary drive D:\

I guess I should edit the Docker Daemon configuration.

Docker Daemon Configuration

I tried to add "graph": "/D/docker". Docker started correctly but I couldn't pull any image because of an error

open /D/docker/tmp/GetImageBlob135686954: no such file or directory

How to tell docker to use another path to store its images, etc ?

Community
  • 1
  • 1
foobar443
  • 2,339
  • 3
  • 23
  • 31

13 Answers13

175

Docker Desktop now can use WSL 2 Backend. In this mode, you need to move the wsl data.

In my case (Windows10 with Docker Desktop) none of the above solutions helped me, but I found the solution; run these commands.

This command changes the docker directory to drive D: (don't forget to quit docker desktop first)

wsl --shutdown
wsl --export docker-desktop-data docker-desktop-data.tar
wsl --unregister docker-desktop-data
wsl --import docker-desktop-data D:\docker-new-repo\ docker-desktop-data.tar --version 2

And now you can delete .tar file

There is a very good blog post explaining everything:

https://dev.to/kimcuonthenet/move-docker-desktop-data-distro-out-of-system-drive-4cg2

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
Saeed
  • 3,415
  • 3
  • 24
  • 41
  • 7
    Thanks for pointing me in the right direction. Worked for me. But it needed a few more steps that I got from https://dev.to/kimcuonthenet/move-docker-desktop-data-distro-out-of-system-drive-4cg2 – Milind Mar 22 '21 at 15:42
  • 4
    Thanks. it did setup the distro at new location. Howevers the old distro "ext4.vhdx" is still getting updates and size keeps increasing. How can we stop this? – aCiD Apr 11 '21 at 10:16
  • 6
    There are 3 modes of Docker Desktop: Linux container with WSL, Linux container with Hyper-V, and Windows container. This solution works for **Linux container with WSL** where configuration is managed by WSL. [see information from Docker Docs](https://docs.docker.com/docker-for-windows/#resources) – Luki B. Subekti May 11 '21 at 00:57
  • For me the last command ends with an error `The specified network name is no longer available.` – jira Sep 14 '21 at 09:36
  • This answer has the most upvotes so is it the recommended way? – Justin Mar 09 '22 at 14:12
  • I would like to ask if restoring Docker to default settings will reset the modifications in this answer? – Justin Mar 09 '22 at 15:01
  • great! thanks! data in ```C:\Users\\AppData\Local\Docker\wsl``` moved to D: drive, my C: drive is safe – Ismynr Mar 10 '22 at 14:35
  • Also, the same but with more details you can find here : https://stackoverflow.com/a/63752264/1151741, helps me on windows move wsl2 to another disk – Nigrimmist Jul 22 '22 at 10:44
  • Is there a solution for Windows Containers as well? – mcExchange Nov 18 '22 at 11:41
50

Docker Version : 2.2.0.3 (42716)

  1. Right-click on docker icon on desktop tray

enter image description here

  1. Click on Settings

enter image description here

3 Click on Resources from the left-hand menu then under the Disk Image location click on browse and change the location

  1. Click on apply and restart
  • 45
    The screen in docker desktop 2.3.0.2 doesn't have these configuration – Thadeu Melo May 15 '20 at 21:21
  • well mine still has that option, I updated the docker to 2.3.0.2 – Michika Iranga Perera May 21 '20 at 07:34
  • 4
    Also thought that the screen is missing, but scrolling down helped. The scrolling pane can be hard to see based on theme used... – Slobodan Savkovic May 29 '20 at 22:12
  • 3
    You should disable 'Use the WSL 2 based engine' in Settings -> General to see the ADVANCED options. – David Jung Jun 12 '20 at 05:26
  • 5
    No one here seems to be realizing that Docker Desktop for Windows has two modes: Linux Containers and Windows Containers. (Mode is set in the tray icon context menu.) If you are in Windows containers mode, the disk image location option is not present. – NReilingh Oct 22 '20 at 01:54
  • 7
    I am not in Windows containers (as it needs Windows Pro or Enterprise Build to enable it), but my docker doesn't have these configuration too. ps: docker version: 2.5.0.0 –  Nov 10 '20 at 06:26
  • I didn't have the Disk Image Location option so I changed the WSL2 per @DavidJung and restarted Docker Desktop. Now when Docker restarts, it's immediately crashes and prompts to share the crash report. It tries to restart again and crashes again and now in a loop. – HPWD Aug 30 '21 at 13:25
  • If I change the path to a network drive G:\docker_images, Ducker ist stuck in restart. If I cancel, the old path is shown. Also see https://stackoverflow.com/questions/76092428/docker-desktop-does-not-restart-after-changing-path-for-image-location-to-a-netw – Stefan Apr 28 '23 at 14:11
  • is it just me or this is taking forever ? its been going on for a few hours with no sign of stopping or progress bar or anything... – Max Alexander Hanna May 10 '23 at 14:53
34

In 2020 to "Change Docker native images location on Windows 10 Pro" is:

  1. quit docker desktop
  2. open/edit configuration file C:\ProgramData\Docker\config\daemon.json
  3. add setting "data-root": "D:\\Virtual Machines\\Docker"
  4. now start docker desktop
  5. run the command docker info to see the setting Docker Root Dir: D:\Virtual Machines\Docker
  6. pull docker images e.g.: docker pull mongo
  7. you can find the downloaded images in folder D:\Virtual Machines\Docker\windowsfilter
J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
Robin Thomas
  • 535
  • 5
  • 6
33

I found a solution here

Docker native, on Windows, runs in a Hyper-V virtual machine.

Move existing docker VM

I have to move the VM used by docker to the desired location. I did this using the GUI of Hyper-V manager. The VM for docker is called MobyLinuxVM.

  • Right-click MobyLinuxVM
  • Select Move
  • Select desired location

Set location of futures Hyper-V VMs

And to be sure futures VMs of Hyper-V will be stored on my secondary drive, I followed those instructions

In a powershell terminal (destination folders must exist)

SET-VMHOST –computername <computer> –virtualharddiskpath 'D:\Hyper-V_Virtual-Hard_Disks' SET-VMHOST –computername <computer> –virtualmachinepath 'D:\Hyper-V_VMs'

foobar443
  • 2,339
  • 3
  • 23
  • 31
  • 1
    It moves back to the original directory whenever I reboot or restart Docker – Pascal Jun 22 '19 at 00:47
  • 1
    When restarting docker after moving the vm, the hdd location is set back to the default, ending to the creation of a new empty virtual hdd. Obviously, all existing docker stuffs disappears. The workaround for me was to make a symlink in default location pointing the deported one. – Harps Oct 23 '19 at 10:12
  • This does not work if docker works with WSL2 support, right? – vinkomlacic Apr 27 '22 at 09:53
21

Edit the Docker Daemon configuration and use "data-root": "D:\\docker" instead of "graph": "/D/docker".
That will move all the newly downloaded images to D:\docker folder.

For Old Docker version use graph "graph": "D:\\docker", "graph" has been deprecated.

Nerdroid
  • 13,398
  • 5
  • 58
  • 69
  • Does this work for Docker enterprise on Windows 2019 Servers? Specifically, Docker version 19.03.5, build 2ee0c57608. – tRuEsAtM Jan 20 '21 at 17:55
15

There is an easier way to do this: Go to Docker Settings > Advanced > Change "Disk image location" and click "Apply" when prompted. Docker engine will shut down the VM and move it for you to the new location.

Warning: new location must not be compressed. If it is then Docker will not show you any error, just won't change location.

Sean Dong
  • 575
  • 9
  • 16
  • 12
    what docker version you use? cause i dont have Advance – Mostafa Jan 04 '19 at 06:00
  • 3
    I have been trying this and when I apply the changes, Docker simply sets it back to the location in `c:\Users\Public\Documents` where it wants everything by default – uglycoyote Mar 30 '19 at 05:21
  • 17
    has no advanced option – Idemax Feb 17 '20 at 15:02
  • Be careful, and if possible, do a backup. I lost all of my containers and had to revert into factory settings. – danielarend Aug 17 '20 at 14:25
  • 1
    In Docker Community v2.3.x, the click path would be ```Docker > Settings > Resources > Disk Image location``` (you may need to scroll down to see the 'Disk Image Location' option. – derekbaker783 Aug 28 '20 at 12:04
  • 11
    Why I'm not seeing these advance options (I'm running on WSL 2) – Indranil Gayen Nov 20 '20 at 21:25
  • 1
    For those with WSL 2 check this answer: https://stackoverflow.com/a/66314636/1577343 it worked for me – Eduard Florinescu Jun 07 '21 at 10:49
  • 3
    "The Advanced tab is only available in Hyper-V mode, because in WSL 2 mode and Windows container mode these resources are managed by Windows. In WSL 2 mode, you can configure limits on the memory, CPU, and swap size allocated to the WSL 2 utility VM." Reason why you are not able to see advance options. – Vinay Verma Sep 16 '21 at 12:23
9

None of these steps worked for me. After reboot or a Docker restart, it would move back to the original path. What worked for me is using Junction

stop docker engine

create a target folder in the new location:

mkdir d:\docker\vhd

copy the folder Virtual Hard Disks to the target folder

rename (and backup) the original folder

rename “C:\Users\Public\Documents\Hyper-V\Virtual hard disks” “C:\Users\Public\Documents\Hyper-V\Virtual hard disks_backup”

create a hard symbolic link (junction)

junction.exe "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks" "d:\docker\vhd\Virtual Hard Disks"

start docker engine

Pascal
  • 2,944
  • 7
  • 49
  • 78
6

For Those looking in 2020. The following is for Windows 10 Machine:

  1. In the global Actions pane of Hyper-V Manager click Hyper-V Settings…
  2. Under Virtual Hard Disks change the location from the default to your desired location.
  3. Under Virtual Machines change the location from the default to your desired location, and click apply.

enter image description here

  1. Click OK to close the Hyper-V Settings page.
Abdullah
  • 479
  • 5
  • 5
5

If issues using the Docker Desktop GUI, when using Hyper-V:

  1. Shutdown Docker Desktop
  2. Edit c:\users\[USERNAME]\AppData\Roaming\Docker\settings.json
    • You need to edit dataFolder entry. Use Double backslashes.
    • eg: "dataFolder": "D:\\Demo\\Hyper-V\\DockerDesktop\\DockerDesktop"
  3. Restart Docker Desktop

You can also use the above if Docker Desktop loses track of where you data folder is, as the GUI doesn't allow you to set it to a previously used location.

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
River Rock
  • 79
  • 1
  • 1
2

I would recommend looking at Microsoft documentation docker engine on windows, it's the daemon.json file that allows to change the setting "data-root": "".

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
codea
  • 1,439
  • 1
  • 17
  • 31
1

From: https://github.com/microsoft/WSL/issues/4699#issuecomment-658369676

He created a symlink pointing to the new folder location. By running:

$ErrorActionPreference = "Stop"
$newLocation = "E:\VMs\WSL2\"

cd "~\AppData\Local\Docker\wsl\data"
wsl --shutdown
Optimize-VHD .\ext4.vhdx -Mode Full
mkdir $newLocation -Force
mv ext4.vhdx $newLocation
cd ..
rm "data"
New-Item -ItemType SymbolicLink -Path "data" -Target $newLocation

He also wrote a blog post going into more detail: http://nuts4.net/post/moving-wsl2-vhdx-file-to-a-different-location

0

2023 Update:

Open up docker desktop GUI. On the left sidebar, there's a tab titled Extensions followed by 3 dots/Menu. click it and a toggle menu will appear, click on settings. Click the Resources tab and then click Browse. Update your image location. Here's what you'll see.

enter image description here

Mujeeb Ishaque
  • 2,259
  • 24
  • 16
-2

Just configuration from Docker Desktop worked for me (Latest Version V20.10.8)

Steps

  1. Go to settings
  2. Select 'Docker Engine' option
  3. Add property "data-root": "D:\\Docker" in configuration file
  4. Apply and Restart

Settings

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94