title: How to install bcrypt on docker image?
body: <p>I am having issue installing bcrypt on my docker. </p>
  
  <p>my node application need bcrypt do encrypt user data. I used <code>npm install bcrypt --save</code> to install on my local computer and this seem to be working well. Now I want to dockerize my application.</p>
  
  <p>My Dockerfile look like this. </p>
  
  <pre><code>FROM  node:10.12.0
  RUN npm install --global node-pre-gyp
  RUN apt-get update &amp;&amp; apt-get install -y build-essential &amp;&amp; apt-get install -y python &amp;&amp; npm install
  
  RUN mkdir -p /usr/src/app
  RUN whoami
  
  WORKDIR /usr/src/app
  
  COPY . /usr/src/app
  
  RUN npm install nodemon -g --save
  RUN npm install 
  RUN node -v
  RUN npm install bcrypt -g --save
  # RUN npm install bcrypt - g --save
  # CMD [ 'pm2', 'start', 'app.js' '--log-date-format' "'YYYY-MM-DD HH:mm Z'" ]
  CMD [ "nodemon" ]
  </code></pre>
  
  <p>my package.json file looks like this:</p>
  
  <pre><code>{
    "name": "api",
    "version": "1.0.0",
    "description": "Best app",
    "main": "app.js",
    "scripts": {
      "test": "echo \"Error: no test specified\" &amp;&amp; exit 1"
    },
    "author": "name",
    "license": "ISC",
    "dependencies": {
      "bcrypt": "^3.0.2",
      "config": "^2.0.1",
      "dotenv": "^6.1.0",
      "express": "^4.16.4",
      "joi": "^14.0.0",
      "joi-objectid": "^2.0.0",
      "jsonwebtoken": "^8.3.0",
      "lodash": "^4.17.11",
      "mongoose": "^5.3.4",
      "multer": "^1.4.1",
      "nodemailer": "^4.7.0",
      "nodemon": "^1.18.4",
      "stripe": "^6.15.0"
    }
  }
  </code></pre>
  
  <p>When I try to build with <code>docker build .</code></p>
  
  <p>This error occurs:</p>
  
  <pre><code>Sending build context to Docker daemon   226 MB
  Step 1/12 : FROM node:10.12.0
   ---&gt; a2b9536415c2
  Step 2/12 : RUN npm install --global node-pre-gyp
   ---&gt; Using cache
   ---&gt; c76403d98dd5
  Step 3/12 : RUN apt-get update &amp;&amp; apt-get install -y build-essential &amp;&amp; apt-get install -y python &amp;&amp; npm install
   ---&gt; Using cache
   ---&gt; 7926c2a74e90
  Step 4/12 : RUN mkdir -p /usr/src/app
   ---&gt; Using cache
   ---&gt; 5ecb4eb08f05
  Step 5/12 : RUN whoami
   ---&gt; Using cache
   ---&gt; e5ff9b23c652
  Step 6/12 : WORKDIR /usr/src/app
   ---&gt; Using cache
   ---&gt; d0f9dd01719b
  Step 7/12 : COPY . /usr/src/app
   ---&gt; 30d30749e5d4
  Removing intermediate container a20cfaca9bb3
  Step 8/12 : RUN npm install nodemon -g --save
   ---&gt; Running in a495bc73977f
  /usr/local/bin/nodemon -&gt; /usr/local/lib/node_modules/nodemon/bin/nodemon.js
  
  &gt; nodemon@1.18.7 postinstall /usr/local/lib/node_modules/nodemon
  &gt; node bin/postinstall || exit 0
  
  Love nodemon? You can now support the project via the open collective:
   &gt; https://opencollective.com/nodemon/donate
  
  npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/nodemon/node_modules/fsevents):
  npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
  
  + nodemon@1.18.7
  added 223 packages from 130 contributors in 12.461s
   ---&gt; 9bb36a08bd55
  Removing intermediate container a495bc73977f
  Step 9/12 : RUN npm install
   ---&gt; Running in f544752d8d41
  npm WARN api@1.0.0 No repository field.
  npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
  npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
  
  audited 2580 packages in 3.287s
  found 1 critical severity vulnerability
    run `npm audit fix` to fix them, or `npm audit` for details
   ---&gt; 5982d518a0e8
  Removing intermediate container f544752d8d41
  Step 10/12 : RUN node -v
   ---&gt; Running in a08d0492d376
  v10.12.0
   ---&gt; c41e54a1910c
  Removing intermediate container a08d0492d376
  Step 11/12 : RUN npm install bcrypt -g --save
   ---&gt; Running in 874f9d8d7bcf
  
  &gt; bcrypt@3.0.2 install /usr/local/lib/node_modules/bcrypt
  &gt; node-pre-gyp install --fallback-to-build
  
  node-pre-gyp WARN Using needle for node-pre-gyp https download
  node-pre-gyp WARN Pre-built binaries not installable for bcrypt@3.0.2 and node@10.12.0 (node-v64 ABI, glibc) (falling back to source compile with node-gyp)
  node-pre-gyp WARN Hit error EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/lib'
  gyp WARN EACCES user "undefined" does not have permission to access the dev dir "/root/.node-gyp/10.12.0"
  gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/bcrypt/.node-gyp"
  gyp WARN install got an error, rolling back install
  gyp WARN install got an error, rolling back install
  gyp ERR! configure error
  gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/.node-gyp'
  gyp ERR! System Linux 4.15.0-42-generic
  gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/usr/local/lib/node_modules/bcrypt/lib/binding" "--napi_version=3" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v64"
  gyp ERR! cwd /usr/local/lib/node_modules/bcrypt
  gyp ERR! node -v v10.12.0
  gyp ERR! node-gyp -v v3.8.0
  gyp ERR! not ok
  node-pre-gyp ERR! build error
  node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/usr/local/lib/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64' (1)
  node-pre-gyp ERR! stack     at ChildProcess.&lt;anonymous&gt; (/usr/local/lib/node_modules/bcrypt/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
  node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
  node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:962:16)
  node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
  node-pre-gyp ERR! System Linux 4.15.0-42-generic
  node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/bcrypt/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
  node-pre-gyp ERR! cwd /usr/local/lib/node_modules/bcrypt
  node-pre-gyp ERR! node -v v10.12.0
  node-pre-gyp ERR! node-pre-gyp -v v0.11.0
  node-pre-gyp ERR! not ok
  Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/usr/local/lib/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64' (1)
  npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! bcrypt@3.0.2 install: `node-pre-gyp install --fallback-to-build`
  npm ERR! Exit status 1
  npm ERR!
  npm ERR! Failed at the bcrypt@3.0.2 install script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /root/.npm/_logs/2018-12-07T15_41_19_990Z-debug.log
  The command '/bin/sh -c npm install bcrypt -g --save' returned a non-zero code: 1
  </code></pre>
  
  <p>This is working find on my local ubuntu 18.04, but not on docker.
  Any idea what is wrong ?</p>