74

I am using docker toolbox on Windows 7 to run docker. (docker version 1.9.1)

As it turns out, the docker machine creates its VM at C:\Users\username\.docker\machine\machines\default. As I commit the images, the size of VM at this location bloats up. Since it's Windows, I can't afford the luxury of space on the C drive.

Is there any way I can change the location of the default machine?

Pang
  • 8,605
  • 144
  • 77
  • 113
shrivb
  • 1,391
  • 3
  • 12
  • 20

13 Answers13

61

This is what worked perfectly for me on Windows 7:

  1. Setup the MACHINE_STORAGE_PATH environment variable as the root of the location you want to use for the Docker machines/VMs, cache, etc.
  2. Install Docker Toolbox
  3. Run Docker Quickstart Terminal

Docker Toolbox will now create all the files at the location pointed at by MACHINE_STORAGE_PATH.

UPDATE:

Note that creating a new VM with the new storage path is not ideal, as the Docker Quickstart Terminal scripts don't seem to work with anything not named "default".

If you've already got a VM sitting in the C: drive, then the simplest thing to do would be to go to Oracle VirtualBox and delete the "default" VM, uninstall Docker Toolbox, delete C:\Users\<username>.docker\, and then follow the 3 steps above.

Note: uninstalling and reinstalling Docker Toolbox may not be required. But I haven't tested without it.

Update

To move Docker certificates also, set the DOCKER_CERT_PATH variable to point to the path of the new drive. Thanks to @Nutle for the tip.

Rajesh J Advani
  • 5,239
  • 1
  • 18
  • 32
  • 7
    I'm using windows 10 and this way worked with me too – Ya Basha Jun 13 '16 at 09:30
  • Worked for me too... Note that after uninstalling docker, the VM needs to be stopped via VirtualBox console and removed (Delete all files). Else, docker will give an error and exit during subsequent installation... – SSG Feb 13 '17 at 20:58
  • 1
    Note also that docker-machine assumes that this is the parent directory for the "cache", "certs", and "machines" directories. I personally assumed first that if I put {my-home-directory} as MACHINE_STORAGE_PATH, then docker-machine would create the .docker/machine directory structure I was familiar with underneath. This was not the case. So to get equivalent behavior, I had to set MACHINE_STORAGE_PATH to {my-home-directory}\.docker\machine. – jzheaux Apr 13 '17 at 20:15
  • 1
    Worth noting that it may be necessary to additionally set the environvment variable for the certificates -- ``DOCKER_CERT_PATH``. In my case (w7 x64) it was enough to set it to ``{my_custom_machine_storage_path_link}\certs``. – runr Apr 28 '17 at 11:57
  • 2
    I updated my docker & VM with another directory by simply copying whole .docker folder to D:\DockerEnv & updating MACHINE_STORAGE_PATH appropriately without uninstalling docker / VM For actual start I need to update default.vbox, config.json from `D:\DockerEnv\.docker\machine\machines\default` also VirtualBox.xml from `{USER_HOME}.VirtualBox` – Nikhil Jul 31 '17 at 19:55
  • 1
    Thank you. I can confirm that uninstalling is not required. Just remove default vm `docker-machine rm default` and create a new one after setting the environment vatiables. – Dmitry Smorzhok Dec 12 '17 at 06:58
  • Worked perfectly on Windows 10. I set these variables, removed default vm, and created a new default vm. `MACHINE_STORAGE_PATH` `D:\docker\.docker\machine`, `DOCKER_CERT_PATH` `D:\docker\.docker\machine\machines\default` – Rafi Jul 02 '19 at 10:09
56

You can move .docker directory to another drive and create a junction point to it.

Please note that regular shortcut will not work.

For example:

Move .docker directory from C:\Users\username to D:\

and run:

C:\Users\username>mklink /j .docker D:\.docker
Junction created for .docker <<===>> D:\.docker
TheEsnSiavashi
  • 1,235
  • 1
  • 12
  • 24
vlado
  • 661
  • 5
  • 2
31

Since 2015, there is now (June 2017) Hyper-V, which allows you to define where you want your VHDX files:

See Docker for Windows 1.13.0, 2017-01-19 (stable):

VHDX file containing images and non-host mounted volumes can be moved (using “advanced” tab in the UI)

That will modify the %APPDATA%\Docker\settings.json with a line:

"MobyVhdPathOverride":"C:\\Users\\Public\\Documents\\Hyper-V\\New folder\\MobyLinuxVM.vhdx"

https://cdn-enterprise.discourse.org/docker/uploads/default/optimized/2X/6/6193445cf15811ce18317c727af258adb2d16c9d_1_690x447.jpg

See this thread for more.


Original answer

Currently 2015 , docker-machine forces the use of %USERPROFILE%:
See libmachine/mcnutils/utils.go#L17-L25

As commented in issue 499:

In the meantime, how will users be able to specify where the .docker/machine/* files are stored?

you can by specifying --storage-path on the command line or using the environment variable MACHINE_STORAGE_PATH.

(You can see it implemented in PR 1941)

Joost Den Boer points out in the comments

Just tried '-s <path>' on a Mac and it seems to work fine.
What might not be obvious is that the path option goes before the command.
Running "docker-machine -s /Volumes/other/location' create --driver=virtualbox" created a new VirtualBox image at the other location.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • tried that `$ docker-machine --storage-path "F:\folder1\folder2\folder3"` but no joy yet. I downloaded the latest docker toolbox for windows from [here](https://www.docker.com/docker-toolbox). Is the [PR 1941](https://github.com/docker/machine/pull/1941/files) part of the latest public download? – shrivb Nov 26 '15 at 09:13
  • @shrivb you can also copy from https://github.com/docker/machine/releases the https://github.com/docker/machine/releases/download/v0.5.1/docker-machine_windows-amd64.zip and unzip it anywhere you want. But yes, PR 1941 should be part of 0.5.1. – VonC Nov 26 '15 at 09:18
  • 1
    @shrivb try with setting `MACHINE_STORAGE_PATH` environment variable (instead of using the `--storage-path` option), to see if that make a difference. – VonC Nov 26 '15 at 09:19
  • tried using the following command in bash `$ set MACHINE_STORAGE_PATH = "F:\user\DevOps\VM\machine"` but doing a env | grep MACHINE gave me only `DOCKER_MACHINE_NAME=default` . User [this](https://docs.docker.com/machine/reference/env/) as a reference. – shrivb Nov 26 '15 at 09:42
  • 4
    In bash, that would be `export MACHINE_STORAGE_PATH=F:\user\DevOps\VM\machine`: no space, no quotes. But try it in a regular CMD session: `set MACHINE_STORAGE_PATH=F:\user\DevOps\VM\machine`: again, no space, no quotes. – VonC Nov 26 '15 at 09:44
  • @shrivb Then try and create a docker machine to see if that do store it in the expected path. – VonC Nov 26 '15 at 09:45
  • 1
    Just tried '-s ' on a Mac and it seems to work fine. What might not be obvious is that the path option goes before the command. Running "docker-machine -s /Volumes/other/location' create --driver=virtualbox" created a new VirtualBox image at the other location. – Joost den Boer Jan 13 '16 at 14:12
  • @JoostdenBoer Thank you for your feedback. I have included your comment in the answer for more visibility. – VonC Jan 13 '16 at 15:14
  • 1
    Running on Windows, the -s flag did create the new machine in the specified path as expected. However, docker does not seem to know about it after that, "docker-machine ls" does not list it, and I cannot "docker-machine start" it ("Host does not exist" error). Running Docker Toolbox version 1.9.1i – Denial Jan 25 '16 at 23:12
  • 4
    Instant update: I additionally exported MACHINE_STORAGE_PATH, and now can see my machine listed via "docker-machine ls". Unclear if the original -s flag was necessary. – Denial Jan 25 '16 at 23:17
  • I've change the drive and docker-machine ls now lists the new location fine, but docker commands result in certificate errors because it's looking for ca.pem in the old location?? – andrea Feb 23 '16 at 18:25
  • @andrea could you ask a new question, with the exact version of the OS, VirtualBox, and the exact error message that you see? – VonC Feb 23 '16 at 18:28
  • Just did: docker-machine -s D:/docker create --driver=virtualbox default Worked great! – UnNatural Jan 09 '17 at 22:25
23

Simply use the VirtualBox graphic interface to relocate the file disk.vmdk:

enter image description here

  1. Copy file C:\Users\{myUsername}\.docker\machine\machines\default\disk.vmdk into another folder, say F:\docker-image\.
  2. Open VirtualBox, select default VM and open Settings.
  3. Open Storage, select current disk.vmdk and release it (or delete it).
  4. Click on Choose Virtual Hard Disk File... and search for copied file in F:\docker-image\
  5. A Warning occurs: VirtualBox complains of old VM UID then go to menu File, select Virtual Media Manager... and release or remove old disk.vmdk
  6. Retry 4., it's done!
  7. If required by your environment then do the relocation also for boot2docker.iso, Snapshot Folder, Video Capture.
ron190
  • 932
  • 1
  • 13
  • 28
  • 2
    Just worth mentioning that you can do the following steps only when your VM is not running. – zygimantus Jun 05 '18 at 11:41
  • 2
    1) docker-machine.exe stop default 2) Move disk.vmdk in virtualbox UI to new location. (file/manage disk/move) 3) docker-machine.exe start default – MrDywar Apr 25 '19 at 13:16
  • 1
    After hours of debugging the other solutions I try this one and have it working in 5 minutes... – Isaac Pak Oct 05 '20 at 22:51
14

Put these two commands when running docker quick start terminal.

I suppose that your new location is "D:\docker" and your new machine name is "docker1"

export MACHINE_STORAGE_PATH=D:\\docker

docker-machine create --driver=virtualbox docker1

This should create a new machine with specified name in your new location.

ProEns08
  • 1,727
  • 2
  • 19
  • 35
8

I could not get the MACHINE_STORAGE_PATH environment variable method working. It kept complaining about missing certificates when first initialising the machine. Still on Windows 7 so have to use docker-toolbox.

I got around the issue by:

  1. Uninstalling Docker Toolbox and restarting machine
  2. Open up Administrator prompt (Find command prompt, hold shift, choose "Run As Administrator")
  3. Deleting .docker from %USERPROFILE%: rmdir /S %USERPROFILE%.docker
  4. Create folder called .docker elsewhere: mkdir a:\.docker
  5. mklink /J %USERPROFILE%.docker a:\.docker
  6. Close Admin command prompt
  7. Reinstall Docker Toolbox
  8. Use the Docker Quickstart Terminal link to bootstrap everything.
  9. Kitematic can be opened now too (though I had to choose the "Use Virtual Box" option on first error.
paulecoyote
  • 1,723
  • 2
  • 13
  • 11
3

I have had a bit of trouble with any of the solutions above but this is what worked for me:

  • define the MACHINE_STORAGE_PATH environment variable to point to your desired directory/folder.
  • Install docker-toolbox as normal, if this works for you then fine, but for me it was still installing inside .docker directory.
  • To fix this I have then stopped and removed the default machine that was created along with .docker folder from the Users directory.
  • Edited the start.sh script and added the line at the top:

e.g.

export MACHINE_STORAGE_PATH=D:\\Docker
  • Run the Docker Quickstart Terminal Shortcut, which rebuilt the default machine inside the desired folder
Marcs
  • 3,393
  • 4
  • 29
  • 39
DrGun
  • 31
  • 4
2

This answer is for people using Docker Toolbox (Windows 10 Home Build 1909, You can follow below steps for docker installation and then location change. I am not adding any images)

Install Docker Toolkit and VM must be installed with Admin Privileges after the installation of docker toolkit (*because Docker Toolkit also installs VM but it's of lower version and creates a problem with other iso files, u can uncheck also, in that case, *). Now we have to change the location of disk.vmdk and update the new location in VM.

  • Install Docker Toolbox from here. Follow the instructions provided
  • Now Download Virtual Machine v6+
  • Install Virtual Machine as Administrator (By Right-clicking and selecting there)
  • Goto place where your VirtualBox.exe(Not the installer) is present and right-click on it (you can find from the shortcut created on your Desktop)
  • goto properties --> compatibility --> change setting for all users --> select run this program as administrator
  • Now close the VM if it's running and run the Kitematic, If it fails (it will probably) then select option provided related to VM (only 2 options are there)
  • This time it will work, now close it

Changing the Location where Images will be downloaded

  • open your VM and close a newly running image default (right-click -> close --> power off)
  • copy paste your disk.vmdk file (for me it's present at C:\Users\Dell\.docker\machine\machines\default\disk.vmdk) to a place where you want to store your images that you download (basically disk.vmdk is what will grow in size when you are using docker)
  • Now we need to tell the VM also about this change
  • Right-click default image and goto settings
  • Select Storage
  • remove disk.vmdk attachment by right-clicking --> remove (that was the older path binded disk.vmdk)
  • click on file --> virtual media manager and remove disk.vmdk from here also (Now VM don't know if such a disk.vmdk thing exsists)
  • Right-click default image --> storage --> add hard disk (this option is just above that iso image)
  • Now select that disk.vmdk that you have pasted somewhere
  • Now run your docker cli and then run this command docker run hello-world
  • If no error is there then it's all done
  • You can verify size by checking the sizes of those two vmdk disks and then pulling some new images



I have written a very descriptive answer starting from installation because I did face some issues and so wanted to make it highly straight forward for the others.
You can delete your disk.vmdk disk (older one) from your C drive if you want to

1UC1F3R616
  • 353
  • 1
  • 10
1

Create file called c:\programdata\docker\config\daemon.json with content below where e:\images is location where do you want to store all you images etc. restart docker.

{ "graph": "e:\\images" }

This Worked like a charm

Reference - https://forums.docker.com/t/where-are-images-stored/9794/11

xmojmr
  • 7,696
  • 5
  • 29
  • 51
0

These answers are out of date, as of the latest release. The location is configurable in the Settings user interface.

https://github.com/docker/for-win/issues/333

Paul Knopf
  • 8,943
  • 21
  • 69
  • 131
0

I found lots of these answers were out of data, at least they did not work in my environment: win10 PRO, docker desktop community 2.0.0.3. Finally, I resolved this problem by this method:

  1. uninstall docker

  2. open Hyper-V manager (press WIN key and then enter "Hyper")

  3. Change the default virtual hard disk locations in the Hyper-V settings (not on the VM settings) and confirm

  4. install docker

  5. check the disk image location in advanced options of docker settings

lengxuehx
  • 1,220
  • 1
  • 16
  • 22
  • 1
    on Windows 10 Pro , docker desktop and docker toolbox have hyper-v as the VM driver by default. Most of these answers are for docker toolbox with VirutalBox driver, on Windows that do not have hyper-v. – bigdataolddriver Sep 23 '19 at 15:33
0

I use windows 10 and Docker desktop (community) Version 2.0.0.0, I want to move vhdx file to another Drive.

Right click over Docker Desktop -> Settings enter image description here then the Docker Desktop UI will open go to Advance -> Disk image location enter image description here just change the path to new destination, the whole process was smooth and fast for me - it's automatically copy the vhdx file from original path to new path restart docker and all work as expected  

Yohan
  • 783
  • 6
  • 13
0

For windows 7:

  • copy paste your disk.vmdk file (for me it's present at C:\Users\name.docker\machine\machines\default\disk.vmdk) to a place where you want to store your images that you download (basically disk.vmdk is what will grow in size when you are using docker)

  • in Virtualbox Right-click default image and goto settings Select Storage remove disk.vmdk attachment by right-clicking --> remove

  • click on file --> virtual media manager and remove disk.vmdk from here also

  • Right-click default image --> storage --> add hard disk (this option is just above that iso image)Now select that disk.vmdk that you have pasted somewhere

  • change now this path in config.json (C:\Users\name.docker\machine\machines\default\config.json) change the storage path with this new one where u put the location of your hard disk ( "StorePath": "F:\docker-image")

save.