Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

docker - What's the best way to share files from Windows to Boot2docker VM?

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.

Enter image description here

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/
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...