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

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

问题描述

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

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

我还发现boot2docker无法保留我的更改.例如,我在重新启动boot2docker之后创建一个文件夹/temp.该文件夹消失了,非常不方便.

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.

在Windows上有一些代码,但需要对其进行泊坞处理时,您会怎么做?

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

-更新---

---update---

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

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是在VirtualBox上运行的小型Linux VM.因此,您必须先与Boot2Docker VM本身共享代码,然后才能在Docker(在Windows VM中运行)中使用文件(从Windows)中.

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.

要这样做,请在关机时将Windows文件夹装入到VM(此处假定VM名称为default):

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

(或者,您也可以打开VirtualBox UI并将文件夹安装到VM中,就像在屏幕快照中一样!)

现在ssh进入Docker快速入门终端的Boot2Docker VM:

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

docker-machine ssh default

然后执行挂载:

  1. 在VM内创建一个文件夹:sudo mkdir /VM_share
  2. 将Windows文件夹安装到该文件夹​​:sudo mount -t vboxsf win_share /VM_share
  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

之后,您可以在Boot2Docker VM中访问C:/work:

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

cd /VM_share

现在您的代码已经存在于VM中,您可以将其作为卷安装到容器中,从而可以在Docker中使用它:

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

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

Or by using it while building your Docker image:

...
ADD /my_windows_folder /folder
...

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

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