将文件从 Windows 共享到 Boot2docker VM 的最佳方式是什么? [英] What's the best way to share files from Windows to Boot2docker VM?

查看:24
本文介绍了将文件从 Windows 共享到 Boot2docker VM 的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Windows 上准备好了我的代码,但我发现分享到 boot2docker 并不容易.

我还发现 boot2docker 无法持久化我的更改.例如,我在重新启动 boot2docker 后创建一个文件夹 /temp.这个文件夹不见了,很不方便.

当您在 Windows 上有一些代码,但需要对它们进行 dockerize 时,您的方法是什么?

---更新---

我尝试更新 VirtualBox 中的设置并重新启动 boot2docker,但它在我的机器上不起作用.

<前>docker@boot2docker:/$ ls -al/c共 4 个drwxr-xr-x 3 根 60 Jun 17 05:42 ./drwxrwxr-x 17 根 400 六月 17 05:42 ../dr-xr-xr-x 1 码头工人 4096 Jun 16 09:47 用户/

解决方案

Boot2Docker 是一个运行在 VirtualBox 上的小型 Linux VM.因此,在您可以在 Docker(在此 VM 中运行)中使用您的文件(来自 Windows)之前,您必须首先与 Boot2Docker VM 本身共享您的代码.

为此,您需要在虚拟机关闭时挂载您的 Windows 文件夹到虚拟机(这里假设虚拟机名称为 default):

C:/Program Files/Oracle/VirtualBox/VBoxManage sharedfolder 添加默认 -name win_share -hostpath c:/work

(或者,您也可以打开 VirtualBox UI 并将文件夹挂载到您的 VM,就像您在屏幕截图中所做的一样!)

现在ssh进入Docker Quickstart Terminal的Boot2Docker VM:

docker-machine ssh 默认

然后执行挂载:

  1. 在虚拟机内创建一个文件夹:sudo mkdir/VM_share
  2. 安装 Windows 文件夹:sudo mount -t vboxsf win_share/VM_share

之后,您可以在 Boot2Docker 虚拟机中访问 C:/work:

cd/VM_share

现在您的代码已存在于您的 VM 中,您可以将其与 Docker 一起使用,方法是将其作为卷安装到容器中:

docker-machine ssh 默认docker run --volume/VM_share:/folder/in/container some/image

或者在构建 Docker 镜像时使用它:

<代码>...添加/my_windows_folder/folder...

<小时>

I have make my code ready on Windows, but I find it's not easy to share to boot2docker.

I also find that boot2docker can't persistent my changes. For example, I create a folder, /temp, after I restart boot2docker. This folder disappears, and it's very inconvenient.

What is your way when you have some code on Windows, but you need to dockerize them?

---update---

I try to update the setting in VirtualBox and restart boot2docker, but it's not working on my machine.

docker@boot2docker:/$ ls -al /c
total 4
drwxr-xr-x    3 root     root            60 Jun 17 05:42 ./
drwxrwxr-x   17 root     root           400 Jun 17 05:42 ../
dr-xr-xr-x    1 docker   staff         4096 Jun 16 09:47 Users/

解决方案

Boot2Docker is a small Linux VM running on VirtualBox. So before you can use your files (from Windows) in Docker (which is running in this VM), you must first share your code with the Boot2Docker VM itself.

To do so, you mount your Windows folder to the VM when it is shutdown (here a VM name of default is assumed):

C:/Program Files/Oracle/VirtualBox/VBoxManage sharedfolder 
add default -name win_share -hostpath c:/work

(Alternatively you can also open the VirtualBox UI and mount the folder to your VM just as you did in your screenshot!)

Now ssh into the Boot2Docker VM for the Docker Quickstart Terminal:

docker-machine ssh default

Then perform the mount:

  1. Make a folder inside the VM: sudo mkdir /VM_share
  2. Mount the Windows folder to it: sudo mount -t vboxsf win_share /VM_share

After that, you can access C:/work inside your Boot2Docker VM:

cd /VM_share

Now that your code is present inside your VM, you can use it with Docker, either by mounting it as a volume to the container:

docker-machine ssh default
docker run --volume /VM_share:/folder/in/container some/image

Or by using it while building your Docker image:

...
ADD /my_windows_folder /folder
...


这篇关于将文件从 Windows 共享到 Boot2docker VM 的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆