title: Dockerizing a NodeJS app: package.json works fine locally but not inside container
body: <p>This is the <code>package.json</code> of my Node app:</p>
  
  <pre><code>{
      "name": "my-graphql-app",
      "version": "1.0.0",
      "description": "My Node GraphQL APP",
      "private": true,
      "license": "UNLICENSED",
      "scripts": {
          "start": "npm run run:watch",
          "build": "webpack",
          "build:watch": "webpack --watch",
          "run": "node ./dist/app.js",
          "run:watch": "nodemon ./dist/app.js"
      },
      "dependencies": {
          "@babel/core": "^7.8.4",
          "@babel/polyfill": "^7.8.3",
          "@babel/preset-env": "^7.8.4",
          "apollo-server-express": "^2.10.1",
          "babel-loader": "^8.0.6",
          "body-parser": "^1.19.0",
          "cors": "^2.8.5",
          "express": "^4.17.1",
          "graphql": "^14.6.0",
          "mysql2": "^2.1.0",
          "nodemon": "^2.0.2",
          "npm-run-all": "^4.1.5",
          "sequelize": "^5.21.5",
          "webpack-cli": "^3.3.11"
      },
      "devDependencies": {
          "webpack": "^4.41.6",
          "webpack-node-externals": "^1.7.2"
      }
  }
  </code></pre>
  
  <p>This is working fine when I run <code>npm install</code> and <code>npm start</code> on my local machine (in case it matters, I am running it on Mac OS Catalina 10.15.3). My local node version is <code>v11.10.1</code>.</p>
  
  <p>I am going crazy trying to make the same Node app work inside a docker container. I have made many different attempts, tweaking the <code>package.json</code> and <code>Dockerfile</code>, but I always end up with some npm install error or import error.</p>
  
  <p>I am trying to spin up the containers (I also have a MySQL container) using <code>docker-compose up --build</code>.</p>
  
  <p>This is my <code>Dockerfile</code>:</p>
  
  <pre><code>FROM node:12
  
  EXPOSE 5000
  
  WORKDIR /graphql_api
  
  COPY package.json .
  RUN npm install
  
  COPY . /graphql_api
  
  CMD npm start
  </code></pre>
  
  <p>This is my <code>docker-compose.yml</code>:</p>
  
  <pre><code>version: '3'
  services:
      database:
          image: mysql:5.7
          environment:
              - 'MYSQL_ROOT_PASSWORD=pwd'
              - 'MYSQL_DATABASE=testdb'
              - 'MYSQL_USER=user'
              - 'MYSQL_PASSWORD=pwd'
          volumes:
              - ./db:/docker-entrypoint-initdb.d
          restart: always
          ports:
              - 8006:3306
      graphql_api:
          build: ./graphql_api
          container_name: graphql_api
          restart: always
          volumes:
              - ./graphql_api:/graphql_api
              - /graphql_api/node_modules
          ports:
              - "5000:5000"
          depends_on:
              - database
  </code></pre>
  
  <p>(The MySQL container starts up perfectly fine, by the way, and the database itself is correctly initialised with the all the tables I have defined in my <code>init.sql</code> file.)</p>
  
  <p>As soon as the build process reaches the <code>RUN npm install</code> point, I always get this warning:</p>
  
  <pre><code>npm WARN deprecated core-js@2.6.11: core-js@&lt;3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
  </code></pre>
  
  <p>Then I get a bunch of messages like these ones</p>
  
  <pre><code>npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/chokidar/node_modules/fsevents):
  npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
  npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/watchpack/node_modules/chokidar/node_modules/fsevents):
  npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
  npm WARN optional SKIPPING OPTIONAL DEPENDENCY: abbrev@1.1.1 (node_modules/watchpack/node_modules/fsevents/node_modules/abbrev):
  npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/graphql_api/node_modules/watchpack/node_modules/fsevents/node_modules/abbrev' -&gt; '/graphql_api/node_modules/watchpack/node_modules/fsevents/node_modules/.abbrev.DELETE'
  npm WARN optional SKIPPING OPTIONAL DEPENDENCY: ansi-regex@2.1.1 (node_modules/watchpack/node_modules/fsevents/node_modules/ansi-regex):
  </code></pre>
  
  <p>(I didn't copypaste them all because there are really <strong>a lot</strong>.)</p>
  
  <p>After those I get the message</p>
  
  <pre><code>added 785 packages from 486 contributors and audited 8930 packages in 26.85s
  </code></pre>
  
  <p>which makes me think that <code>npm install</code> did in fact have some effect despite the previous messages.</p>
  
  <p>However, when the build process reaches the <code>CMD npm start</code>, this happens:</p>
  
  <pre><code>graphql_api    | &gt; my-graphql-app@1.0.0 start /graphql_api
  graphql_api    | &gt; npm-run-all --parallel build:watch run:watch
  graphql_api    |
  graphql_api    | sh: 1: npm-run-all: not found
  graphql_api    | npm ERR! code ELIFECYCLE
  graphql_api    | npm ERR! syscall spawn
  graphql_api    | npm ERR! file sh
  graphql_api    | npm ERR! errno ENOENT
  graphql_api    | npm ERR! my-graphql-app@1.0.0 start: `npm-run-all --parallel build:watch run:watch`
  graphql_api    | npm ERR! spawn ENOENT
  graphql_api    | npm ERR!
  graphql_api    | npm ERR! Failed at the my-graphql-app@1.0.0 start script.
  graphql_api    | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  </code></pre>
  
  <p>I have also tried building the container while starting from a <code>node:11</code> image instead of a <code>node:12</code> image, to match the Node version I have installed locally, but the result is the same.</p>
  
  <p>I am really at a loss here: I have tried changing many things around after googling and looking at other StackOverflow answers (for example, the addition of <code>"private": true</code> in <code>pacakge.json</code> comes from an answer I found here to a similar question) but I still cannot get this container to run.</p>