1

I have a bind mount at /home/quant/mounted_folder with a fstab like this:

/mnt/d/some_folder /home/quant/mounted_folder none bind

I can confirm that the folder mounts correctly on the host:

DESKTOP-NHBC022@quant: ~/mounted_folder $ ls
foo.txt bar.txt

Reproducing the problem:

Take this docker-compose.yml file:

version: "3.3"
services:
  env:
    image: debian:latest
    volumes:
      - "/home/quant:/root/host"

The contents of /root/host/code appears empty inside the container:

DESKTOP-NHBC022@quant: ~ $ docker compose run env bash -c 'ls -al /root/host/code'
total 28
drwxr-xr-x  2 1000 1000  4096 Jun 18 12:28 .
drwxr-xr-x 17 1000 1000 24576 Jun 18 12:56 ..

Workaround:

If I skip the docker-compose and use just docker run, it seems to work:

DESKTOP-NHBC022@quant: ~ $ docker run -v /home/quant/:/root/host debian:latest bash -c 'ls -al /root/host/code'
total 24
drwxrwxrwx  1 1000 1000  4096 Jun 18 08:59 .
drwxr-xr-x 17 1000 1000 24576 Jun 18 13:00 ..
-rwxrwxrwx  1 1000 1000     0 Feb 11  2021 foo.txt
-rwxrwxrwx  1 1000 1000     0 Jun 18 08:59 bar.txt

How can I make sure that mounted paths on the host correctly appear inside the docker container if they're subdirectories of paths mounted in the container?

I'm running docker 20.10.1 on windows 10 WSL.

1
  • I've never ran the new "compose" command within docker, looks cool, but it's pretty new. Have you tried docker-compose?
    – Peter Turner
    Jun 20, 2022 at 16:25

1 Answer 1

0

My guess is different defaults to bind mount propagation between docker run and docker compose. Try setting it to rslave or shared in your compose file:

version: "3.3"
services:
  env:
    image: debian:latest
    volumes:
      - "/home/quant:/root/host:rslave"
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.