Answers: <p>My guess is different defaults to <a href="https://docs.docker.com/storage/bind-mounts/#configure-bind-propagation" rel="nofollow noreferrer">bind mount propagation</a> between <code>docker run</code> and <code>docker compose</code>. Try setting it to rslave or shared in your compose file:</p>
  <pre class="lang-yaml prettyprint-override"><code>version: &quot;3.3&quot;
  services:
    env:
      image: debian:latest
      volumes:
        - &quot;/home/quant:/root/host:rslave&quot;
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2022-06-25T17:50:30.297Z
Answers: Related issue in compose: https://github.com/docker/compose/issues/9380
Answers: BMitch
Answers: CC BY-SA 4.0
Answers: 2022-06-25T17:46:25.260Z
Answers: 2022-06-25T17:46:25.260Z
Answers: BMitch
Body: <p>I have a bind mount at /home/quant/mounted_folder with a fstab like this:</p>
  <pre><code>/mnt/d/some_folder /home/quant/mounted_folder none bind
  </code></pre>
  <p>I can confirm that the folder mounts correctly on the host:</p>
  <pre><code>DESKTOP-NHBC022@quant: ~/mounted_folder $ ls
  foo.txt bar.txt
  </code></pre>
  <p><strong>Reproducing the problem:</strong></p>
  <p>Take this <code>docker-compose.yml</code> file:</p>
  <pre><code>version: &quot;3.3&quot;
  services:
    env:
      image: debian:latest
      volumes:
        - &quot;/home/quant:/root/host&quot;
  </code></pre>
  <p>The contents of <code>/root/host/code</code> appears empty inside the container:</p>
  <pre><code>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 ..
  </code></pre>
  <p><strong>Workaround:</strong></p>
  <p>If I skip the docker-compose and use just docker run, it seems to work:</p>
  <pre><code>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
  </code></pre>
  <p>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?</p>
  <p>I'm running docker 20.10.1 on windows 10 WSL.</p>
  
Comments: CC BY-SA 4.0
Comments: 2022-06-20T16:25:34.017Z
Comments: I've never ran the new "compose" command within docker, looks cool, but it's pretty new. Have you tried `docker-compose`?
Comments: Peter Turner
Tags: <docker><docker-compose>
Title: bind mount from host not appearing in docker container when using compose
UserDisplayName: quant
ThreadText: # bind mount from host not appearing in docker container when using compose
  
  (Asked by: username_0 on 2022-06-18)
  
  I have a bind mount at /home/username_0/mounted\_folder with a fstab like this:
  
  ```
  /mnt/d/some_folder /home/username_0/mounted_folder none bind
  
  ```
  
  I can confirm that the folder mounts correctly on the host:
  
  ```
  DESKTOP-NHBC022@username_0: ~/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/username_0:/root/host"
  
  ```
  
  The contents of `/root/host/code` appears empty inside the container:
  
  ```
  DESKTOP-NHBC022@username_0: ~ $ 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@username_0: ~ $ docker run -v /home/username_0/:/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.
  
  **Tags:** docker, docker-compose
  
  > **Comments:**
  > **username_1**: I've never ran the new "compose" command within docker, looks cool, but it's pretty new. Have you tried `docker-compose`?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-06-25. Score: 0
  
  My guess is different defaults to [bind mount propagation](https://docs.docker.com/storage/bind-mounts/#configure-bind-propagation) between `docker run` and `docker compose`. Try setting it to rslave or shared in your compose file:
  
  ```yaml
  version: "3.3"
  services:
    env:
      image: debian:latest
      volumes:
        - "/home/username_0:/root/host:rslave"
  
  ```
  
  > **Comments:**
  > **username_2**: Related issue in compose: https://github.com/docker/compose/issues/9380  
  
  ---
  
  