Bikash Lama
Bikash Lama

Reputation: 187

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.

Upvotes: 2

Views: 3299

Answers (3)

Nessy
Nessy

Reputation: 41

Like @Damo, I faced a similar issue due to docker-compose in WSL not binding volumes correctly, resulting in the volumes not mounting at all.

In WSL2 and with Docker Desktop, you can simply change from using the separate docker-compose to using docker compose (note, no hyphen), which is a recent plugin added to Docker to handle this.

Upvotes: 0

Damo
Damo

Reputation: 6443

I had a very similar error and it turned out to be an issue with docker-compose as installed in WSL. The version of docker-compose installed inside WSL was not handling volume binding correctly. This was fixed by removing /usr/local/bin/docker-compose from the WSL install and instead aliasing the windows exe alias docker-compose="/mnt/c/Program\ Files/Docker/Docker/resources/bin/docker-compose.exe"

Upvotes: 3

Krzysztof Zawadzki
Krzysztof Zawadzki

Reputation: 89

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

Upvotes: 3

Related Questions