title: Cannot find module error for a node js app running in a docker environment
body: <p>This application is written in ES6 and compile to ES5 using babel. The build files stored in the following order inside the build folder. the dockerfile reside in the outside the build folder.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>-build
  ---public
  ---server
  ---shared
  ---package.json
  -Dockerfile</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is my docker file.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>FROM node:8.9-alpine
  ENV     NODE_ENV production
  
  WORKDIR /usr/src/app
  ADD    ./build/  /usr/src/app
  
  RUN npm install --production --silent
  
  RUN ls /usr/src/app/
  RUN ls /usr/src/app/server/
  
  EXPOSE 3000
  
  CMD  ["node", "/usr/src/app/server/index.js", "--config", "/usr/src/app/config.json"]</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is the output I get when running the image build command.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>Sending build context to Docker daemon  16.08MB
  Step 1/9 : FROM node:8.9-alpine
   ---&gt; 406f227b21f5
  Step 2/9 : ENV     NODE_ENV production
   ---&gt; Using cache
   ---&gt; 090d3e742281
  Step 3/9 : WORKDIR /usr/src/app
   ---&gt; Using cache
   ---&gt; fa2a344bd8ee
  Step 4/9 : ADD    ./build/  /usr/src/app
   ---&gt; 93559e34a45a
  Step 5/9 : RUN npm install --production --silent
   ---&gt; Running in ebc2b6b2ba1a
  added 212 packages in 15.212s
  Removing intermediate container ebc2b6b2ba1a
   ---&gt; b49180988a07
  Step 6/9 : RUN ls /usr/src/app/
   ---&gt; Running in b140530cb8ca
  build-info.json
  node_modules
  package-lock.json
  package.json
  public
  server
  shared
  Removing intermediate container b140530cb8ca
   ---&gt; 0712e1b84e1a
  Step 7/9 : RUN ls /usr/src/app/server/
   ---&gt; Running in b6570fbc8d2c
  auth
  configuration
  database
  files
  index.js
  sessions
  users
  utils
  Removing intermediate container b6570fbc8d2c
   ---&gt; c49775551756
  Step 8/9 : EXPOSE 3000
   ---&gt; Running in 9318dfc0f183
  Removing intermediate container 9318dfc0f183
   ---&gt; ad20aec92973
  Step 9/9 : CMD  ["node", "/usr/src/app/server/index.js", "--config", "/usr/src/app/config.json"]
   ---&gt; Running in fa6c2e388906
  Removing intermediate container fa6c2e388906
   ---&gt; ba1ced3be150
  Successfully built ba1ced3be150
  Successfully tagged tiqri:myclaim
  SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.</code></pre>
  </div>
  </div>
  </p>
  
  <p>After image created, i start the image using the following command.
  "docker run -d -v C:\portal\environments\development:/usr/src/app/ -p 3000:80 f057e4bc8191"
  There is volume map for config files.</p>
  
  <p>But the container, not running. when I check the logs, it shows the following error. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>C:\portal&gt;docker logs c819d39fea61
  module.js:540
      throw err;
      ^
  
  Error: Cannot find module '/usr/src/app/server/index.js'
      at Function.Module._resolveFilename (module.js:538:15)
      at Function.Module._load (module.js:468:25)
      at Function.Module.runMain (module.js:684:10)
      at startup (bootstrap_node.js:187:16)
      at bootstrap_node.js:608:3</code></pre>
  </div>
  </div>
  </p>
  
  <p>I couldn't figure out why giving this error even though all folders are in place in the docker container(RUN ls- shows the folder structure in the container).
  still, I couldn't start the container because of this error.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Based on the answer given by @Marcos Casagrande, made changes to the docker file and container run command as follows. Now I'm getting a new error.</p>
  
  <p>After made changes in the Dockerfile.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>FROM node:8.9-alpine
  ENV     NODE_ENV production
  
  WORKDIR /usr/src/app
  
  ADD    ./build/  /usr/src/app
  RUN npm install --production --silent &amp;&amp; mv node_modules ../
  
  RUN mkdir /usr/src/app/environments
  RUN mkdir /usr/src/app/environments/development
  
  RUN ls /usr/src/app/
  RUN ls /usr/src/app/server/
  
  EXPOSE 3000
  
  CMD  ["node", "/usr/src/app/server/index.js", "--config", "/usr/src/app/environments/development/config.json"]</code></pre>
  </div>
  </div>
  </p>
  
  <p>container run command changed as follows,
  "docker run -d -v C:\portal\environments\development:/usr/src/app/environments/development -p 3000:80 ca290d67ff34"</p>
  
  <p>Then I get the following error when checking the logs. The container does not start yet.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>/usr/src/app/environments/development/config.json
  /usr/src/app/environments/development/config.json
  fs.js:646
    return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                   ^
  
  Error: ENOENT: no such file or directory, open '/usr/src/app/environments/development/config.json'
      at Object.fs.openSync (fs.js:646:18)
      at Object.fs.readFileSync (fs.js:551:33)
      at loadJSON (/usr/src/node_modules/convict/lib/convict.js:364:25)
      at /usr/src/node_modules/convict/lib/convict.js:501:17
      at Array.forEach (&lt;anonymous&gt;)
      at Object.loadFile (/usr/src/node_modules/convict/lib/convict.js:500:13)
      at Object.&lt;anonymous&gt; (/usr/src/app/server/configuration/configuration.js:156:19)
      at Module._compile (module.js:643:30)
      at Object.Module._extensions..js (module.js:654:10)
      at Module.load (module.js:556:32)</code></pre>
  </div>
  </div>
  </p>