更改 Docker 机器位置 - Windows

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33933107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:22:06  来源:igfitidea点击:

Change Docker machine location - Windows

windowsdockerdocker-machinedocker-toolbox

提问by shrivb

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

我在 Windows 7 上使用 docker 工具箱来运行 docker。(码头工人版本 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.

事实证明,docker 机器在 C:\Users\username\.docker\machine\machines\default 处创建了它的 VM。当我提交图像时,此位置的 VM 大小会膨胀。由于它的 Windows,无法承受 C 盘上的奢侈空间。

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

有什么办法可以更改默认机器的位置吗?

回答by Rajesh J Advani

This is what worked perfectly for me on Windows 7:

这对我来说在 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
  1. 将 MACHINE_STORAGE_PATH 环境变量设置为要用于 Docker 机器/VM、缓存等的位置的根目录。
  2. 安装 Docker 工具箱
  3. 运行 Docker 快速入门终端

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

Docker Toolbox 现在将在 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".

请注意,使用新存储路径创建新 VM 并不理想,因为 Docker 快速入门终端脚本似乎不适用于任何未命名为“默认”的内容。

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.

如果您已经在 C: 驱动器中安装了一个 VM,那么最简单的方法是转到 Oracle VirtualBox 并删除“默认”VM,卸载 Docker Toolbox,删除 C:\Users\<username>。 docker\,然后按照上面的 3 个步骤操作。

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

注意:可能不需要卸载和重新安装 Docker Toolbox。但没有它我还没有测试过。

Update

更新

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

要移动 Docker 证书,请将DOCKER_CERT_PATH变量设置为指向新驱动器的路径。感谢@Nutle 的提示。

回答by vlado

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

您可以将.docker目录移动到另一个驱动器并创建一个连接点。

Please note that regular shortcut will not work.

请注意,常规快捷方式将不起作用。

For example:

例如:

Move .dockerdirectory from C:\Users\usernameto D:\

.docker目录从移动C:\Users\usernameD:\

and run:

并运行:

C:\Users\username>mklink /j .docker D:\.docker
Junction created for .docker <<===>> D:\.docker

回答by VonC

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

自 2015 年以来,现在(2017 年 6 月)Hyper-V允许您定义VHDX文件的位置

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

请参阅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)

可以移动包含图像和非主机安装卷的 VHDX 文件(使用 UI 中的“高级”选项卡)

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

这将%APPDATA%\Docker\settings.json用一行修改:

"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

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

目前 2015 年,docker-machine 强制使用%USERPROFILE%
libmachine/mcnutils/utils.go#L17-L25

As commented in issue 499:

正如第 499 期所评论的:

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

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

同时,用户如何能够指定.docker/machine/*文件的存储位置?

您可以通过--storage-path在命令行上指定或使用环境变量MACHINE_STORAGE_PATH

(You can see it implemented in PR 1941)

(你可以看到它在PR 1941 中实现)

Joost Den Boerpoints out in the comments

Joost的书斋波尔指出在评论

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.

刚刚-s <path>在 Mac 上尝试了 ' ',它似乎工作正常。
可能不明显的是 path 选项位于 command 之前
运行“ docker-machine -s /Volumes/other/location' create --driver=virtualbox”在另一个位置创建了一个新的 VirtualBox 映像。

回答by ron190

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

只需使用 VirtualBox 图形界面重新定位文件disk.vmdk

enter image description here

在此处输入图片说明

  1. Copy file C:\Users\{myUsername}\.docker\machine\machines\default\disk.vmdkinto another folder, say F:\docker-image\.
  2. Open VirtualBox, select defaultVM and open Settings.
  3. Open Storage, select current disk.vmdkand 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.
  1. 将文件复制C:\Users\{myUsername}\.docker\machine\machines\default\disk.vmdk到另一个文件夹中,例如F:\docker-image\.
  2. 打开VirtualBox,选择defaultVM 并打开Settings
  3. 打开Storage,选择当前disk.vmdk并释放它(或删除它)。
  4. 单击Choose Virtual Hard Disk File...并搜索复制的文件F:\docker-image\
  5. 出现警告:VirtualBox 抱怨旧的 VM UID,然后转到菜单File,选择Virtual Media Manager...并释放或删除旧的disk.vmdk
  6. 重试4.,大功告成!
  7. 如果您的环境需要,则还对 boot2docker.iso、快照文件夹、视频捕获进行重新定位。

回答by ProEns08

Put these two commands when running docker quick start terminal.

在运行 docker 快速启动终端时输入这两个命令。

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

我想你的新位置是“D:\docker”,你的新机器名称是“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.

这应该在您的新位置创建具有指定名称的新机器。

回答by paulecoyote

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.

我无法让 MACHINE_STORAGE_PATH 环境变量方法工作。首次初始化机器时,它一直抱怨缺少证书。仍然在 Windows 7 上,所以必须使用 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.
  1. 卸载 Docker Toolbox 并重启机器
  2. 打开管理员提示符(找到命令提示符,按住shift,选择“以管理员身份运行”)
  3. 从 %USERPROFILE% 中删除 .docker: rmdir /S %USERPROFILE%.docker
  4. 在别处创建名为 .docker 的文件夹: mkdir a:\.docker
  5. mklink /J %USERPROFILE%.docker a:\.docker
  6. 关闭管理员命令提示符
  7. 重新安装 Docker 工具箱
  8. 使用 Docker 快速入门终端链接来引导一切。
  9. Kitematic 现在也可以打开(尽管我必须在第一个错误时选择“使用虚拟框”选项。

回答by DrGun

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

我对上述任何解决方案都遇到了一些麻烦,但这对我有用:

  • define the MACHINE_STORAGE_PATHenvironment 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 .dockerdirectory.
  • To fix this I have then stopped and removed the default machine that was created along with .dockerfolder from the Users directory.
  • Edited the start.shscript and added the line at the top:
  • 定义MACHINE_STORAGE_PATH环境变量以指向所需的目录/文件夹。
  • 像往常一样安装 docker-toolbox,如果这对你有用,那很好,但对我来说它仍然安装在.docker目录中。
  • 为了解决这个问题,我停止并删除了与.docker用户目录中的文件夹一起创建的默认机器。
  • 编辑start.sh脚本并在顶部添加一行:

e.g.

例如

export MACHINE_STORAGE_PATH=D:\Docker
  • Run the Docker Quickstart Terminal Shortcut, which rebuilt the default machine inside the desired folder
  • 运行 Docker Quickstart Terminal Shortcut,它在所需文件夹中重建了默认机器

回答by lengxuehx

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:

我发现很多这些答案都没有数据,至少它们在我的环境中不起作用:win10 PRO,docker desktop community 2.0.0.3。最后,我通过这种方法解决了这个问题:

  1. uninstall docker

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

  3. Change the default virtual hard disk locationsin the Hyper-Vsettings (not on the VM settings) and confirm

  4. install docker

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

  1. 卸载码头工人

  2. 打开 Hyper-V 管理器(按 WIN 键,然后输入“Hyper”)

  3. Hyper-V设置中更改默认虚拟硬盘位置(而不是在 VM 设置中)并确认

  4. 安装码头工人

  5. 在 docker 设置的高级选项中检查磁盘映像位置

回答by Satish Kumar Nadarajan

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.

创建名为 c:\programdata\docker\config\daemon.json 的文件,内容如下,其中 e:\images 是您要存储所有图像的位置等。重新启动 docker。

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

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

This Worked like a charm

这就像一个魅力

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

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

回答by Yohan

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

我使用 Windows 10 和 Docker 桌面(社区)版本 2.0.0.0,我想将 vhdx 文件移动到另一个驱动器。

Right click over Docker Desktop -> Settings enter image description herethen the Docker Desktop UI will open go to Advance -> Disk image location enter image description herejust 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 ?

右键单击 Docker 桌面 -> 设置, 在此处输入图片说明然后 Docker 桌面 UI 将打开转到高级 -> 磁盘映像位置 在此处输入图片说明只需将路径更改为新目标,整个过程对我来说既流畅又快速 - 它会自动从原始路径复制 vhdx 文件到新路径重新启动 docker 并按预期工作?