Change Docker machine location - Windows

2019-01-29 23:02发布

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. And as I commit the images the size of VM at this location bloats up. Since its Windows, cant afford the luxury of space on the C drive.

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

8条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-29 23:34

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

查看更多
The star\"
3楼-- · 2019-01-29 23:35

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.

查看更多
倾城 Initia
4楼-- · 2019-01-29 23:35

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.

查看更多
Animai°情兽
5楼-- · 2019-01-29 23:37

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
查看更多
ゆ 、 Hurt°
6楼-- · 2019-01-29 23:38

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.
查看更多
爷的心禁止访问
7楼-- · 2019-01-29 23:52

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.

查看更多
登录 后发表回答