How do I map volume outside C:\Users to container on Windows?

最后都变了- 提交于 2019-11-30 14:16:07

问题


I'm doing server side development and my workspace is located in D: because I'm not a fan of storing data on C: but just can't find a way to map d:\Workspace to /home/workspace

I've tried creating a symblink from C:\Users\username to D:\Workspace by:

  1. map C:\Users\username\Workspace to /home/workspace
  2. Stop container
  3. rename C:\Users\username\Workspace
  4. Create symlink named Workspace to D:\Workspace
  5. Start container

At first Docker worked fine during that session until I restart Boot2Docker, then start the container I'd get "C:\Users\username\Workspace file exists".

I think this is one Docker's issue but anyways I want to map outside C:\Users.


回答1:


  • Share workspace between host and Boot2Docker virtual machine $ boot2docker down $ cd "C:\Program Files\Oracle\VirtualBox" $ VBoxManage sharedfolder add boot2docker-vm --name mydata --hostpath "D:\Workspace" $ boot2docker up

  • Mount shared folder $ boot2docker ssh 'sudo mkdir -p /data' $ boot2docker ssh 'sudo mount -t vboxsf -o "defaults,uid=33,gid=33,rw" mydata /data'

  • Create data-only container. Docker best practices always recommends you use data-only containers. You can reuse already available data-only containers: $ docker run --volume /data:/data --name mydata dylanlindgren/docker-laravel-data

  • If you want this change to be permanent, you need to add last command inside startup config file /var/lib/boot2docker/bootlocal.sh sleep 10 && sudo mount -t vboxsf -o "defaults,uid=33,gid=33,rw" mydata /data docker start mydata

Then, you will have your workspace mounted at /data

You can find more documentation about VirtualBox Guest Additions in Boot2Docker here.




回答2:


Updated answer for now, as boot2docker has been deprecated. The same is now achieved with docker-machine.

The answer is described here: https://github.com/docker/machine/issues/1814

Basically, after mounting the shared folders in the Virtual Box UI, you need to run the following commands in a command prompt:

# Note the extra / at the beginning of the path because of msys/MinGW.
docker-machine.exe ssh default 'sudo mkdir --parents //e/Documents/workspace'
docker-machine.exe ssh default 'sudo mount -t vboxsf e/Documents/workspace //e/Documents/workspace'


来源:https://stackoverflow.com/questions/30586949/how-do-i-map-volume-outside-c-users-to-container-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!