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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nick Doulgeridis
  • 583
  • 1
  • 16
  • 31
  • 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: https://github.com/boot2docker/boot2docker#folder-sharing – Kurt Raschke Feb 19 '16 at 01:30

1 Answers1

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)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So in docker-compose.yml the volumes have nothing to do with windows but its to mount from linux vm to containers only? – Nick Doulgeridis Feb 19 '16 at 10:03
  • Yes, they operate in the Linux world of boot2docker only – VonC Feb 19 '16 at 10:04
  • 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? – Nick Doulgeridis Feb 19 '16 at 12:05
  • @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) – VonC Feb 19 '16 at 12:21
  • 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. – Nick Doulgeridis Feb 19 '16 at 12:26
  • @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. – VonC Feb 19 '16 at 12:32