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

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

问题描述

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

从"手动共享目录作为docker卷安装点":

您需要:

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

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