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条回答
倾城 Initia
2楼-- · 2019-01-29 23:54

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.
查看更多
不美不萌又怎样
3楼-- · 2019-01-29 23:55

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
查看更多
登录 后发表回答