Docker Compose mount Windows folder
Asked Answered
L

1

8

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:\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.

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

Lavinialavinie answered 19/2, 2016 at 1:20 Comment(1)
Remember that with boot2docker, there are two layers of abstraction: a Linux virtual machine, then the Docker engine running in that VM. Docker Compose doesn't know anything about the world outside the VM where Docker is running, and can't, for example, configure VirtualBox shared folders. There is some discussion of this in the boot2docker documentation: github.com/boot2docker/boot2docker#folder-sharingCabinetmaker
I
9

My objective is to Mount C:\data\www 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:\data\ww' --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)

Ivetteivetts answered 19/2, 2016 at 6:11 Comment(6)
So in docker-compose.yml the volumes have nothing to do with windows but its to mount from linux vm to containers only?Lavinialavinie
Yes, they operate in the Linux world of boot2docker onlyIvetteivetts
I have a serious issue, my mounting folder is displaying OK to boot2docker VM machine but if I add or edit a file from Widows this file is not updating back to VM machine Any ideas?Lavinialavinie
@Crash21 Not on the top of my head, but please: make a new question with all the screenshots and details and (including the version of boot2docker, version of VirtualBox used, and the commands used to declare the mount)Ivetteivetts
One question only for this one :) When i install docker toolbox should i install VirtualBox if I already have it installed? I haven't and wonder if by any way this makes a bug.Lavinialavinie
@Crash21 no, no need for toolbox either: just get the latest VirtualBox and docker-machine (one exe to copy from ). That is all that you need.Ivetteivetts

© 2022 - 2024 — McMap. All rights reserved.