Docker Compose挂载Windows文件夹 [英] Docker Compose mount Windows folder
问题描述
我在Windows中使用Docker Toolbox,并尝试将Windows文件夹安装在docker-compose.yml文件中,如下所示:
I am using Docker Toolbox in Windows and am trying to mount a Windows folder in a docker-compose.yml file like this:
nginx:
image: nginx:latest
container_name: test_server
ports:
- "80:80"
volumes:
- /sss:/c/data/www:ro
environment:
- VIRTUAL_HOST=test.local
我的目标是将C:\data\www
挂载到已经由Docker Toolbox创建的boot2docker VM映像上,然后从那里安装到其中的nginx容器中.
My objective is to mount C:\data\www
to the boot2docker VM image which is already created by Docker Toolbox and then from there to the nginx container inside of it.
很遗憾,它无法正常工作.我在boot2docker映像中找到一个文件夹sss,但是它没有指定我的Windows数据就为空.
Unfortunately it's not working. I get a folder sss inside the boot2docker image, but it's empty without targeting to my Windows data.
我做错了什么?在开发过程中是否有更好的做法以便在Windows上使用Docker(因此您需要在Windows,Docker VM(boot2docker)和Docker容器之间共享代码)?
What am I doing wrong? Is there a better practice in order to use Docker on Windows while you are developing (so you need to share code between Windows, the Docker VM (boot2docker) and Docker containers)?
推荐答案
我的目标是将
C:\data\www
挂载到boot2docker VM映像
My objective is to Mount
C:\data\www
to boot2docker VM image
您需要:
-
修改您的VirtualBox VM(确保先停止它):
modify your VirtualBox VM (make sure it is stopped first):
VBoxManage sharedfolder add <machine name/id> --name <mount_name> --hostpath <host_dir> --automount
# in your case
/c/Program\ Files/Oracle/VirtualBox/VBoxManage.exe sharedfolder add default --name www --hostpath 'C:\data\ww' --automount
向您的boot2docker虚拟机添加自动挂载:
- 编辑/创建(作为
root
)/mnt/sda1/var/lib/boot2docker/bootlocal.sh
,(sda1
可能与您有所不同) -
添加
- Edit/create (as
root
)/mnt/sda1/var/lib/boot2docker/bootlocal.sh
, (sda1
may be different for you) Add
mkdir -p <local_dir>
mount -t vboxsf -o defaults,uid=`id -u docker`,gid=`id -g docker` <mount_name> <local_dir
(您可能必须在此处添加umask
)
(you might have to add the umask
as in here)
这篇关于Docker Compose挂载Windows文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!