title: Docker: bind mounts not working as I expected
body: <p>Most of the times I use Docker with volumes. But Now I am trying bind mounts for the first time and they are not working as I expected. I'm probably missing something or maybe not understanding completely they way they work.</p>
  
  <p>Let's take this example. I have a React app created with <code>create-react-app</code> and it will run with a Rails backend based on a MySQL database. </p>
  
  <p>My directory structure is:</p>
  
  <pre><code>App
  ├── docker
  │   ├── api
  │   │   └── Dockerfile
  │   └── fe
  │       ├── Dockerfile
  │       ├── package.json
  │       ├── package-lock.json
  │       ├── public
  │       ├── README.md
  │       └── src
  ├── docker-compose.yml
  </code></pre>
  
  <p>I started by creating the <code>docker-compose.yml</code> file like this:</p>
  
  <pre><code>version: "3.7"
  
  services:
  
    web:
      build: ./docker/fe/.
      ports: ["80:3000"]
      volumes:
        - type: bind
          source: "./docker/fe"
          target: "/app"
  </code></pre>
  
  <p>As you may see, I am mapping the directory <code>./docker/fe</code>, where the React frontend is, to <code>/app</code>.</p>
  
  <p>Inside <code>./docker/fe</code> is the Dockerfile:</p>
  
  <pre><code>FROM node:8
  
  WORKDIR /app
  
  RUN npm install
  
  CMD ["npm","start"]
  </code></pre>
  
  <p>I was expecting this to work, because my app files are all inside <code>/app</code>, mapped to <code>./docker/fe</code>. At least I thought they would be! But when I run the <code>docker-compose up --build</code> command at the command line I get a build error, because it says there is no <code>package.json</code> file inside the <code>/app</code> directory.</p>
  
  <p>On the other hand, when I use this other version of <code>Dockerfile</code></p>
  
  <pre><code>FROM node:8
  
  WORKDIR /app
  
  ADD package.json .
  
  ADD package-lock.json .
  
  RUN npm install
  
  ADD . .
  
  CMD ["npm","start"]
  </code></pre>
  
  <p>this problem won't happen. It will find the <code>package.json</code> file and build the app correctly. But it won't run!</p>
  
  <p>The fact is, it will say it can't find the React scripts. And it is no surprise, since when it is finished there is no <code>node_modules</code> directory inside <code>./docker/fe</code> as it would be expected after running <code>npm install</code>.</p>
  
  <p>I am confused.</p>
  
  <ul>
  <li><p>Am I missing something about the bind mounts?</p></li>
  <li><p>Why do I need to ADD <code>package.json</code> to the WORKDIR if this directory is associated with the host directory where this file already is?</p></li>
  <li><p>Why I don't have a <code>node_modules</code> directory inside <code>./docker/fe</code> after <code>npm install</code>?</p></li>
  </ul>