Change Docker machine location - Windows

67,557

Solution 1

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.

Solution 2

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

Solution 3

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.

Solution 4

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.

Solution 5

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.

Share:
67,557
shrivb
Author by

shrivb

A simple guy trying to lead a simple life. @shrivb

Updated on July 05, 2022

Comments

  • shrivb
    shrivb almost 2 years

    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?

  • shrivb
    shrivb over 8 years
    tried that $ docker-machine --storage-path "F:\folder1\folder2\folder3" but no joy yet. I downloaded the latest docker toolbox for windows from here. Is the PR 1941 part of the latest public download?
  • VonC
    VonC over 8 years
    @shrivb you can also copy from github.com/docker/machine/releases the github.com/docker/machine/releases/download/v0.5.1/… and unzip it anywhere you want. But yes, PR 1941 should be part of 0.5.1.
  • VonC
    VonC over 8 years
    @shrivb try with setting MACHINE_STORAGE_PATH environment variable (instead of using the --storage-path option), to see if that make a difference.
  • shrivb
    shrivb over 8 years
    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 as a reference.
  • VonC
    VonC over 8 years
    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
    VonC over 8 years
    @shrivb Then try and create a docker machine to see if that do store it in the expected path.
  • Joost den Boer
    Joost den Boer over 8 years
    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.
  • VonC
    VonC over 8 years
    @JoostdenBoer Thank you for your feedback. I have included your comment in the answer for more visibility.
  • Denial
    Denial over 8 years
    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
    Denial over 8 years
    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.
  • andrea
    andrea over 8 years
    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??
  • VonC
    VonC over 8 years
    @andrea could you ask a new question, with the exact version of the OS, VirtualBox, and the exact error message that you see?
  • Ya Basha
    Ya Basha about 8 years
    I'm using windows 10 and this way worked with me too
  • UnNatural
    UnNatural over 7 years
    Just did: docker-machine -s D:/docker create --driver=virtualbox default Worked great!
  • SSG
    SSG over 7 years
    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...
  • jzheaux
    jzheaux about 7 years
    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.
  • runr
    runr about 7 years
    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.
  • Nikhil
    Nikhil almost 7 years
    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
  • Dmitry Smorzhok
    Dmitry Smorzhok over 6 years
    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.
  • zygimantus
    zygimantus about 6 years
    Just worth mentioning that you can do the following steps only when your VM is not running.
  • Charles Wood
    Charles Wood over 5 years
    Note that Docker Desktop for Windows is not supported on some OSes, including Windows 10 Home. So these answers are still of use.
  • Sebastian
    Sebastian about 5 years
    +1 Thanks - actually on my Windows 10 (Home with developer mode enabled) using mklink /D also worked - I tried it before I found this answer.
  • Mohsen Afshin
    Mohsen Afshin about 5 years
    Elegant solution
  • MrDywar
    MrDywar about 5 years
    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
  • Rafi
    Rafi almost 5 years
    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
  • James Li
    James Li over 4 years
    Windows without Hyper-v(I can name Windows 7 and Windows 10 Home ) are still of use these answers.
  • James Li
    James Li over 4 years
    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.
  • James Li
    James Li over 4 years
    it is of least effort to move both machine storage path and cert key path . and compatible with any other potential behavior on this path. I upvote this answer three times:)
  • Abdul Mohsin
    Abdul Mohsin almost 4 years
    I think its the easiest option for at-least docker on windows with WSL , tried config like "data-root" but it didn't work.
  • Isaac Pak
    Isaac Pak over 3 years
    After hours of debugging the other solutions I try this one and have it working in 5 minutes...