Change Docker native images location on Windows 10 Pro

DockerWindows 10

Docker Problem Overview


This is not a duplicate of https://stackoverflow.com/questions/33933107/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 ?

Docker Solutions


Solution 1 - Docker

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

Solution 2 - Docker

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

Solution 3 - Docker

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'

Solution 4 - Docker

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

Solution 5 - Docker

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.

Solution 6 - Docker

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.

Solution 7 - Docker

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

Solution 8 - Docker

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.

Solution 9 - Docker

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

Solution 10 - Docker

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.

Solution 11 - Docker

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

Solution 12 - Docker

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionfoobar443View Question on Stackoverflow
Solution 1 - DockerSaeedView Answer on Stackoverflow
Solution 2 - DockerMichika Iranga PereraView Answer on Stackoverflow
Solution 3 - Dockerfoobar443View Answer on Stackoverflow
Solution 4 - DockerRobin ThomasView Answer on Stackoverflow
Solution 5 - DockerNerdroidView Answer on Stackoverflow
Solution 6 - DockerSean DongView Answer on Stackoverflow
Solution 7 - DockerPascalView Answer on Stackoverflow
Solution 8 - DockerAbdullahView Answer on Stackoverflow
Solution 9 - DockercodeaView Answer on Stackoverflow
Solution 10 - DockerRiver RockView Answer on Stackoverflow
Solution 11 - DockerAlberto GuerreroView Answer on Stackoverflow
Solution 12 - DockerAmit IngoleView Answer on Stackoverflow