1

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.

Bikash Lama
  • 177
  • 1
  • 13
  • 1. Have you tried the same using the Windows version of docker-compose.exe? Same result? 2. Where are the directories located? for example /test_folder is in c:\Users\ ..... ? – Carlos Rafael Ramirez Sep 16 '19 at 15:52
  • Yes. The project folder is in c:/Users directory. I do have docker-compose in my windows machine. But, since I am using Ubuntu WSL, I think it uses its own docker-compose. ```C:\Users\bikash>docker-compose --version docker-compose version 1.23.2, build 1110ad01``` – Bikash Lama Sep 16 '19 at 23:35
  • Well, check it if you haven't installed docker-compose for Linux in WSL you are probably using the Windows version from WSL. If you are using the Linux one I don't know what is happening. – Carlos Rafael Ramirez Sep 17 '19 at 12:57
  • docker-compose is installed in my ubuntu wsl. I can see that the docker-compose in docker toolbox for windows and docker-compose for my ubuntu wsl are also different. docker-compose in docker toolbox ```bikash@DESKTOP-VGO9UIB MINGW64 /c/Program Files/Docker Toolbox $ docker-compose --version docker-compose version 1.23.2, build 1110ad01``` docker-compose in ubuntu wsl ``` /c docker-compose --version docker-compose version 1.22.0, build f46880fe``` – Bikash Lama Sep 17 '19 at 23:50

3 Answers3

3

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

  • Thank you for your comments. I will try those methods in future but for the moment the best solution I had was install ubuntu. There's been no issue with running docker on ubuntu and moreover the projects have linux commands in Makefile. I hope windows will give same experience like on linux OS. – Bikash Lama Feb 25 '20 at 09:27
3

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"

Damo
  • 5,698
  • 3
  • 37
  • 55
  • I suppose you're using wsl2 ? afai tried - I canpt do that with wsl1 :( – Radagast the Brown Jul 09 '20 at 15:29
  • `The command 'docker-compose' could not be found in this WSL 1 distro. We recommend to convert this distro to WSL 2 and activate the WSL integration in Docker Desktop settings. See https://docs.docker.com/docker-for-windows/wsl/ for details.` - and that's even when running explicitly as `/mnt/c/Program\ Files/Docker/Docker/resources/bin/docker-compose` – Radagast the Brown Jul 14 '20 at 14:42
  • omg! I found it! there's an sh file in `/mnt/c/Program\ Files/Docker/Docker/resources/bin/` called `docker-compose`, side by side with `docker-compose.exe` which spits this error! I suppose it's trying to act as a fallback of a friendly error but there's probably some invalid assumption about path resolutions that cases this quirk – Radagast the Brown Jul 14 '20 at 14:49
0

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.

Nessy
  • 41
  • 4