问题描述
我在 Windows 中使用 Docker 工具箱,并尝试在 docker-compose.yml 文件中挂载一个 Windows 文件夹,如下所示:
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:datawww
挂载到已经由 Docker Toolbox 创建的 boot2docker VM 映像,然后从那里挂载到其中的 nginx 容器.
My objective is to mount C:datawww
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)?
推荐答案
您需要:
修改您的 VirtualBox 虚拟机(确保先停止它):
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:dataww' --automount
- 编辑/创建(作为
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 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!