Docker Compose 挂载 Windows 文件夹 [英] Docker Compose mount Windows folder

查看:73
本文介绍了Docker Compose 挂载 Windows 文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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)?

推荐答案

我的目标是将 C:datawww 挂载到 boot2docker VM 映像

My objective is to Mount C:datawww to boot2docker VM image

来自手动共享目录作为 docker 卷挂载点":

您需要:

  • 修改您的 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

  • 添加一个自动挂载到您的 boot2docker VM:

    • 编辑/创建(作为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屋!

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