title: Dockerfile COPY from host to container works, but when docker-compose.yml uses volume, the file in container not visible to host
body: <p>Using the context:</p>
  
  <p><a href="https://i.stack.imgur.com/mHBWl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mHBWl.png" alt="test workspace"></a></p>
  
  <p>The goal is to copy test.txt into the container and have it visible in the host's tst folder. The tst folder contains a pre-existing file, tst.txt.</p>
  
  <p>Using Docker application:</p>
  
  <p><a href="https://i.stack.imgur.com/Z9FP7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z9FP7.png" alt="Docker application"></a></p>
  
  <p>Using .dockerignore:</p>
  
  <pre><code>.DS_Store
  .vscode
  .dockerignore
  Dockerfile
  docker-compose.yml
  **/tst
  </code></pre>
  
  <p>Using the Dockerfile:</p>
  
  <pre><code>FROM alpine:latest
  RUN apk add --no-cache bash
  WORKDIR /app
  RUN echo "$(echo "pwd:")" "$(pwd)"  &lt;&lt;-- returns pwd: /app 
  COPY test.txt .
  RUN ls -la . 
  CMD ["sh", "-c", "ls -la ."]
  </code></pre>
  
  <p>Using the docker-compose file:</p>
  
  <pre><code>version: '3.7'
  services:
    app:
      build: .
      volumes:
        - ./tst:/app
  </code></pre>
  
  <p>Running <code>docker-compose up</code> results in:</p>
  
  <pre><code>Creating network "sof_default" with the default driver
  Building app
  Step 1/7 : FROM alpine:latest
  latest: Pulling from library/alpine
  6c40cc604d8e: Downloading [&gt;                                                  
  ----------
  Step 3/7 : WORKDIR /app
  ---&gt; Running in cf58e5a10d23
  Removing intermediate container cf58e5a10d23
  ---&gt; 76fb51298933
  Step 4/7 : RUN echo "$(echo "pwd:")" "$(pwd)"
  ---&gt; Running in 07135f745883
  pwd: /app
  Removing intermediate container 07135f745883
  ---&gt; 45acc1c04a12
  Step 5/7 : COPY test.txt .
  ---&gt; de0ce42397b9
  Step 6/7 : RUN ls -la . &lt;&lt;- the output shows test.txt was copied into the container's /app directory
  ---&gt; Running in 60371e9516c1
  total 12
  drwxr-xr-x    1 root     root          4096 Feb 12 21:25 .
  drwxr-xr-x    1 root     root          4096 Feb 12 21:25 ..
  -rw-r--r--    1 root     root            15 Feb 12 19:19 test.txt
  Removing intermediate container 60371e9516c1
  ---&gt; 3d514dac4f61
  Step 7/7 : CMD ["sh", "-c", "ls -la . &amp;&amp; cat test.txt"]
  ---&gt; Running in db644643a844
  Removing intermediate container db644643a844
  ---&gt; ad9f6988d31d
  
  Successfully built ad9f6988d31d
  Successfully tagged sof_app:latest
  WARNING: Image for service app was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
  Creating sof_app_1 ... done
  Attaching to sof_app_1
  app_1  | total 8
  app_1  | drwxr-xr-x    3 root     root            96 Feb 12 20:50 .
  app_1  | drwxr-xr-x    1 root     root          4096 Feb 12 21:25 ..
  app_1  | -rw-r--r--    1 root     root            45 Feb 12 20:51 tst.txt
  app_1  | cat: can't open 'test.txt': No such file or directory
  sof_app_1 exited with code 1
  </code></pre>
  
  <p>The output shows text.txt was copied into the container, but it is not visible on the host. Why is that?</p>
  
  <p>The <a href="https://docs.docker.com/compose/faq/" rel="nofollow noreferrer">https://docs.docker.com/compose/faq/</a> says</p>
  
  <blockquote>
    <p>"You can have the image include the code using a COPY, and use a volume in your Compose file to include the code from the host during development. The volume overrides the directory contents of the image."</p>
  </blockquote>
  
  <p>I interpret the last sentence to mean that any files or folders in the host's volume override those of the same name in the image's mapped directory.  I would not expect the host directory to completely overwrite the image's directory, deleting any files already in it. Am I mistaken in that assumption?</p>
  
  <p>Any good guidance is appreciated.</p>