Change Docker machine location - Windows
Solution 1
This is what worked perfectly for me on Windows 7:
- Setup the MACHINE_STORAGE_PATH environment variable as the root of the location you want to use for the Docker machines/VMs, cache, etc.
- Install Docker Toolbox
- 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"
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 variableMACHINE_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
:
- Copy file
C:\Users\{myUsername}\.docker\machine\machines\default\disk.vmdk
into another folder, sayF:\docker-image\
. - Open
VirtualBox
, selectdefault
VM and openSettings
. - Open
Storage
, select currentdisk.vmdk
and release it (or delete it). - Click on
Choose Virtual Hard Disk File...
and search for copied file inF:\docker-image\
- A Warning occurs: VirtualBox complains of old VM UID then go to menu
File
, selectVirtual Media Manager...
and release or remove olddisk.vmdk
- Retry
4.
, it's done! - 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.
Comments
-
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 over 8 years
-
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 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 over 8 yearstried using the following command in bash
$ set MACHINE_STORAGE_PATH = "F:\user\DevOps\VM\machine"
but doing a env | grep MACHINE gave me onlyDOCKER_MACHINE_NAME=default
. User this as a reference. -
VonC over 8 yearsIn 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 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 over 8 yearsJust 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 over 8 years@JoostdenBoer Thank you for your feedback. I have included your comment in the answer for more visibility.
-
Denial over 8 yearsRunning 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 over 8 yearsInstant 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 over 8 yearsI'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 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 about 8 yearsI'm using windows 10 and this way worked with me too
-
UnNatural over 7 yearsJust did: docker-machine -s D:/docker create --driver=virtualbox default Worked great!
-
SSG over 7 yearsWorked 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 about 7 yearsNote 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 about 7 yearsWorth 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 almost 7 yearsI 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 over 6 yearsThank 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 about 6 yearsJust worth mentioning that you can do the following steps only when your VM is not running.
-
Charles Wood over 5 yearsNote that Docker Desktop for Windows is not supported on some OSes, including Windows 10 Home. So these answers are still of use.
-
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 about 5 yearsElegant solution
-
MrDywar about 5 years1) 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 almost 5 yearsWorked 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 over 4 yearsWindows without Hyper-v(I can name Windows 7 and Windows 10 Home ) are still of use these answers.
-
James Li over 4 yearson 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 over 4 yearsit 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 almost 4 yearsI 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 over 3 yearsAfter hours of debugging the other solutions I try this one and have it working in 5 minutes...