Search code examples
dockerubuntudocker-composewindows-subsystem-for-linuxdocker-toolbox

docker compose empty volumes (if folder) mount from wsl using docker toolbox


I am running docker compose command to run the app in docker. But, volumes defined in yml are empty. If I mount a single file, it is working. But, when I mount a directory from windows, I can see the directory, but it is empty.

This is my docker-compose command.

docker-compose -f docker-compose.dev.yml -f docker-compose.test.yml -f docker-compose.test.local.yml run --rm app /bin/sh

Below is the content of my yml file:

version: "3"
services:
  app:
    environment:
      - NODE_ENV=test
      - TEST_DB_HOSTNAME=database
      - DB_HOSTNAME=database
      - DB_MIGRATE_ENV=test-docker
    volumes:
      - .jshintignore:/home/test_app/src/.jshintignore
      - .jshintrc:/home/test_app/src/.jshintrc
      - ./nuke-rebuild-test-db.js:/home/gofar/src/nuke-rebuild-test-db.js
      - ./test_folder:/home/test_app/src/test_folder
      - ./database:/home/test_app/src/database
      - ./server:/home/test_app/src/server
      - ./common:/home/test_app/src/common
      - ./coverage:/home/test_app/src/coverage

From above, nuke-rebuild-test-db.js file gets copied into container. I can see test_folder too. But, if I look inside the folder it is empty.

Below are what I have done to make docker work in my Windows 10 Home system where I have docker toolbox.

Below is the config that connects my Ubuntu WSL in my windows machine with Docker Toolbox. enter image description here

For my root directory to be compatible with linux, I have added following to /etc/wsl.conf fiel

[automount]
root = /
options = "metadata"

I have added my application folder in Shared Folders list in Oracle VM Virtual Box too even though the single files are being mounted.

Thanks.


Solution

  • If Your directory from which You run docker-compose is an WSL /home directory this won't work.

    You need to have files outside WSL filesystem which will map to docker image mounted windows shares. By default docker toolbox mounts windows C to /c in boot2docker VM. That's why in WSL it is suggested to add / root automount. So You will have Your C: drive in /c . But no one writes about the /home in wsl and volume mounts in windows docker toolbox ( which is using Virtual Box image for docker )

    The same issue was already discussed here: https://superuser.com/questions/1344407/docker-on-wsl-wont-bind-mount-home/1378927

    https://github.com/docker/for-win/issues/2151