Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

boot2docker - Docker Compose mount Windows folder

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

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.

Unfortunately it's not working. I get a folder sss inside the boot2docker image, but it's empty without targeting to my Windows data.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

From "Manually sharing directory as docker volume mounting point":

You need to:

  • 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
    
  • add an automount to your boot2docker VM:

    • 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
      

(you might have to add the umask as in here)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...