Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 422
Nick Doulgeridis Avatar asked Feb 19 '16 01:02

Nick Doulgeridis


People also ask

How do I mount a folder inside a docker container?

How to Mount Local Directories using docker run -v. Using the parameter -v allows you to bind a local directory. -v or --volume allows you to mount local directories and files to your container. For example, you can start a MySQL database and mount the data directory to store the actual data in your mounted directory.

Where are docker volumes stored Windows?

Where are stored docker volumes Windows? Volumes are stored in a part of the host filesystem which is managed by Docker ( /var/lib/docker/volumes/ on Linux).

Can I mount a file in docker?

Bind mounts have been around since the early days of Docker. Bind mounts have limited functionality compared to volumes. When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its absolute path on the host machine.


1 Answers

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)

like image 115
VonC Avatar answered Oct 13 '22 00:10

VonC