Search code examples
dockerdocker-composeboot2dockerdocker-volume

how to mount a ./project_dir as a volume in docker-compose on windows/virtualbox setup


Docker-compose.yml works well on a mac machine but our developers use both mac and windows computers (windows cannot use hyper-v due to other virtual box requirements.

It is possible to share a folder through VM interface by global path /volume_data_dir

This however causes issues between the environments as mac and production uses relative path ./volume_data_dir as mount point.

I've also tried mounting the folder as /home/docker/volume_data_dir (/home/docker being the home folder of docker inside virtualbox) but no cake.

Thus my question is: what is the directory to share volumes for docker-compose, running inside vmware, to be able to mount the folders using relative path ./volume_data_dir?

the docker-compose.yml in question:

version: '3'
services:
django:
  container_name: server
  restart: always
  depends_on:
    - db
  build:
    context: .
    dockerfile: dockerfile
  image: server
  stdin_open: true
  tty: true
  volumes:
    - ./data:/var/www/data
  ports:
    - "8000:8000"

I've read a very comprehensive answer by GreensterRox ( https://stackoverflow.com/a/48442262/3986395), but unfortunately, it didnt help


Solution

  • A sort of hacky approach that I managed to come up with, was to use the env variables, defined in the docker envfile, to pass the mount path:

    version: '3'
    services:
        django:
          container_name: server
          restart: always
          depends_on:
             - db
        build:
            context: .
            dockerfile: dockerfile
        image: server
        stdin_open: true
        tty: true
        volumes:
            - $VOLUME_MOUNT_PATH:/var/www/data
        ports:
            - "8000:8000"
    

    If anyone has any better solutions, let me know!