How to install bcrypt on docker image? - docker

I am having issue installing bcrypt on my docker.
my node application need bcrypt do encrypt user data. I used npm install bcrypt --save to install on my local computer and this seem to be working well. Now I want to dockerize my application.
My Dockerfile look like this.
FROM node:10.12.0
RUN npm install --global node-pre-gyp
RUN apt-get update && apt-get install -y build-essential && apt-get install -y python && 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" ]
my package.json file looks like this:
{
"name": "api",
"version": "1.0.0",
"description": "Best app",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && 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"
}
}
When I try to build with docker build .
This error occurs:
Sending build context to Docker daemon 226 MB
Step 1/12 : FROM node:10.12.0
---> a2b9536415c2
Step 2/12 : RUN npm install --global node-pre-gyp
---> Using cache
---> c76403d98dd5
Step 3/12 : RUN apt-get update && apt-get install -y build-essential && apt-get install -y python && npm install
---> Using cache
---> 7926c2a74e90
Step 4/12 : RUN mkdir -p /usr/src/app
---> Using cache
---> 5ecb4eb08f05
Step 5/12 : RUN whoami
---> Using cache
---> e5ff9b23c652
Step 6/12 : WORKDIR /usr/src/app
---> Using cache
---> d0f9dd01719b
Step 7/12 : COPY . /usr/src/app
---> 30d30749e5d4
Removing intermediate container a20cfaca9bb3
Step 8/12 : RUN npm install nodemon -g --save
---> Running in a495bc73977f
/usr/local/bin/nodemon -> /usr/local/lib/node_modules/nodemon/bin/nodemon.js
> nodemon#1.18.7 postinstall /usr/local/lib/node_modules/nodemon
> node bin/postinstall || exit 0
Love nodemon? You can now support the project via the open collective:
> 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
---> 9bb36a08bd55
Removing intermediate container a495bc73977f
Step 9/12 : RUN npm install
---> 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
---> 5982d518a0e8
Removing intermediate container f544752d8d41
Step 10/12 : RUN node -v
---> Running in a08d0492d376
v10.12.0
---> c41e54a1910c
Removing intermediate container a08d0492d376
Step 11/12 : RUN npm install bcrypt -g --save
---> Running in 874f9d8d7bcf
> bcrypt#3.0.2 install /usr/local/lib/node_modules/bcrypt
> 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.<anonymous> (/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
This is working find on my local ubuntu 18.04, but not on docker.
Any idea what is wrong ?

Related

How do I install a node module in a Cypress Docker container?

In the path ~/cypress-dockerfile I have the following Dockerfile:
FROM cypress/base:10
RUN npm install --save-dev cypress
WORKDIR /node_modules
RUN npm install sqlite3
RUN $(npm bin)/cypress verify
RUN $(npm bin)/cypress run
I then run docker build . but it stops with the following:
Step 4/6 : RUN npm install sqlite3
---> Running in 13de6b7a4fcf
npm WARN deprecated request#2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
> sqlite3#5.0.0 install /node_modules/sqlite3
> node-pre-gyp install --fallback-to-build
sh: 1: node-pre-gyp: not found
npm WARN enoent ENOENT: no such file or directory, open '/package.json'
npm WARN !invalid#1 No description
npm WARN !invalid#1 No repository field.
npm WARN !invalid#1 No README data
npm WARN !invalid#1 No license field.
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! sqlite3#5.0.0 install: `node-pre-gyp install --fallback-to-build`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the sqlite3#5.0.0 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/2020-08-07T13_28_54_118Z-debug.log
The command '/bin/sh -c npm install sqlite3' returned a non-zero code: 1
I think that I may be in the wrong directory but I am not sure, any help would be appreciated.

npm install returns connection timeout while building docker image

I am trying to make a docker image including newman. I tried to build the image using node:10-alpine, but I got connection refused error while npm install -g newman. This is my docker command:
RUN set http_proxy= && \
set https_proxy= && \
yarn config delete proxy && \
npm config rm https-proxy && \
npm config rm proxy && \
npm config set registry http://registry.npmjs.org/ && \
npm config set strict-ssl false && \
npm cache clean --force && \
npm cache verify && \
npm install -g newman
The full error is:
npm ERR! code ECONNREFUSED
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to https://registry.npmjs.org/newman failed, reason: connect ECONNREFUSED 192.168.14.109:1087
npm ERR! at ClientRequest.req.on.err (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js:68:14)
npm ERR! at ClientRequest.emit (events.js:198:13)
npm ERR! at onerror (/usr/local/lib/node_modules/npm/node_modules/agent-base/index.js:101:9)
npm ERR! at callbackError (/usr/local/lib/node_modules/npm/node_modules/agent-base/index.js:123:5)
npm ERR! at process._tickCallback (internal/process/next_tick.js:68:7)
npm ERR! { FetchError: request to https://registry.npmjs.org/newman failed, reason: connect ECONNREFUSED 192.168.14.109:1087
npm ERR! at ClientRequest.req.on.err (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js:68:14)
npm ERR! at ClientRequest.emit (events.js:198:13)
npm ERR! at onerror (/usr/local/lib/node_modules/npm/node_modules/agent-base/index.js:101:9)
npm ERR! at callbackError (/usr/local/lib/node_modules/npm/node_modules/agent-base/index.js:123:5)
npm ERR! at process._tickCallback (internal/process/next_tick.js:68:7)
npm ERR! message:
npm ERR! 'request to https://registry.npmjs.org/newman failed, reason: connect ECONNREFUSED 192.168.14.109:1087',
npm ERR! type: 'system',
npm ERR! errno: 'ECONNREFUSED',
npm ERR! code: 'ECONNREFUSED',
npm ERR! stack:
npm ERR! 'FetchError: request to https://registry.npmjs.org/newman failed, reason: connect ECONNREFUSED 192.168.14.109:1087\n at ClientRequest.req.on.err (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js:68:14)\n at ClientRequest.emit (events.js:198:13)\n at onerror (/usr/local/lib/node_modules/npm/node_modules/agent-base/index.js:101:9)\n at callbackError (/usr/local/lib/node_modules/npm/node_modules/agent-base/index.js:123:5)\n at process._tickCallback (internal/process/next_tick.js:68:7)' }
npm ERR!
npm ERR! If you are behind a proxy, please make sure that the
npm ERR! 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-03-02T14_57_46_444Z-debug.log
Then I tried to make my image from alpine:3.8 which gives me repository error while apk update. This is my second version:
RUN apk update && apk add --no-cache nodejs npm
RUN npm install -g newman
Full error log is:
Step 5/7 : RUN apk update && apk add --no-cache nodejs npm
---> Running in 6149b2571389
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.8/main: operation timed out
WARNING: Ignoring APKINDEX.adfa7ceb.tar.gz: No such file or directory
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.8/community: operation timed out
WARNING: Ignoring APKINDEX.efaa1f73.tar.gz: No such file or directory
2 errors; 13 distinct packages available
The command '/bin/sh -c apk update && apk add --no-cache nodejs npm' returned a non-zero code: 2
I also tried to build the image with --network=hostoption; but got the same errors in both versions.
Additionally ping dl-cdn.alpinelinux.org works fine on my system.
Besides, restarted the docker service, sudo systemctl restart docker, and tried one more time. Got the same results again.
In my case works with this steps:
In the Host, I change Host Server
/etc/sysctl.conf:
I added
net.ipv4.ip_forward=1
I use
nslookup registry.npmjs.org
Give me the IP 104.16.25.38
Docker Build with IP
docker build . --add-host registry.npmjs.org:104.16.25.38 -t test
In my case works with this below single step,
docker build --add-host registry.npmjs.org:104.16.25.38 -t .

Unable to install appium on ubuntu 16.04 with npm

Showing below error while trying to install appium.
While doing sudo npm install -g appium.
npm ERR! Error: Invalid name: "#gulp-sourcemaps/map-sources"
npm ERR! at ensureValidName (/usr/lib/nodejs/normalize-package-data/lib/fixer.js:284:15)
npm ERR! at Object.module.exports.fixNameField (/usr/lib/nodejs/normalize-package-data/lib/fixer.js:199:5)
npm ERR! at /usr/lib/nodejs/normalize-package-data/lib/normalize.js:29:38
npm ERR! at Array.forEach (native)
npm ERR! at normalize (/usr/lib/nodejs/normalize-package-data/lib/normalize.js:28:15)
npm ERR! at final (/usr/lib/nodejs/read-package-json/read-json.js:310:33)
npm ERR! at then (/usr/lib/nodejs/read-package-json/read-json.js:124:33)
npm ERR! at /usr/lib/nodejs/read-package-json/read-json.js:234:40
npm ERR! at fs.js:268:14
npm ERR! at /usr/lib/nodejs/graceful-fs/graceful-fs.js:103:5
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR! System Linux 3.13.0-137-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "appium"
npm ERR! cwd /home/mosheko
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/mosheko/npm-debug.log
npm ERR! not ok code 0
It might be helpful. Steps to get appium working on ubuntu pc:
Install ruby: Paste the below command at terminal and hit enter
sudo apt-get install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev
Install linux brew:
Paste the below command at terminal and hit enter
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
set path for brew: Type: gedit .bashrc at terminal and copy paste the following into the .bashrc file
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
Install node: Paste the below commands one by one at terminal and hit enter
brew update
brew install node
brew link node
Install Appium:
npm install -g appium npm install wd
To start Appium: Paste the below command at terminal and hit enter
appium
Thanks
Install Java and check the Java version
Step 1 : Java -version
Install Node.js and npm from the Ubuntu repository.
Step 2 : sudo apt update
Step 3 : sudo apt install nodejs
Step 4 : nodejs --version
Out Put : v8.10.0 (version of the Node)
Step 5 : sudo apt install npm
Step 6 : npm --version (npm version).
Step 7 : 3.5.2
Step 8 : sudo npm install -g appium
Step 9 : npm install wd
Step 10 : npm install -g appium-doctor
To verify “Appium” installation we can use appium-doctor. For this, we have to install appium doctor using npm.
Step 11 : appium-doctor
Step 12 : Type “appium” into the terminal and press enter button.
Appium will start.

Electron inside Docker with X11 Forwarding - No Protocol Specified

I am attempting to run the Electron Quick Start in a Docker container with X11 forwarding. I've got all the appropriate packages figured out but when I run the container I get No protocol specified. I'm not sure what I'm missing to get it to work.
Dockerfile
FROM node
RUN apt-get update
RUN apt-get -y install libgtkextra-dev libgconf2-dev libnss3 libasound2 libxtst-dev libxss1 libx11-xcb-dev
WORKDIR /srv
ADD . .
RUN npm install
ENTRYPOINT ["npm", "start"]
Build and Run
docker build -t electron .
docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY electron
Output
npm info it worked if it ends with ok
npm info using npm#4.1.2
npm info using node#v7.7.2
npm info lifecycle electron-quick-start#1.0.0~prestart: electron-quick-start#1.0.0
npm info lifecycle electron-quick-start#1.0.0~start: electron-quick-start#1.0.0
> electron-quick-start#1.0.0 start /srv
> electron .
No protocol specified
npm info lifecycle electron-quick-start#1.0.0~start: Failed to exec start script
npm ERR! Linux 4.8.0-41-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v7.7.2
npm ERR! npm v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! electron-quick-start#1.0.0 start: `electron .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the electron-quick-start#1.0.0 start script 'electron .'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the electron-quick-start package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! electron .
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs electron-quick-start
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls electron-quick-start
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /srv/npm-debug.log
Q: What is the correct way of running Electron apps inside Docker?
In your host machine run xhost local:root then try running your container to run electron

update and install ionic and ios

Try updating to enhance ionic some problems with updating my application in iTunes Connect. Now after updating I get this error when trying to install again and I can not.
MacBook-Pro:app_view_android lixsys$ ionic build ionic
******************************************************
Dependency warning - for the CLI to run correctly,
it is highly suggested to install/upgrade the following:
Install ios-deploy to deploy iOS applications to devices. `npm install -g ios-deploy` (may require sudo)
Unknown platforms: ionic
MacBook-Pro:app_view_android lixsys$ npm install -g ios-deploy
npm ERR! tar.unpack untar error /Users/lixsys/.npm/ios-deploy/1.8.3/package.tgz
npm ERR! Darwin 14.5.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "ios-deploy"
npm ERR! node v0.12.0
npm ERR! npm v2.5.1
npm ERR! path /usr/local/lib/node_modules/ios-deploy
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/ios-deploy'
npm ERR! at Error (native)
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/ios-deploy']
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/ios-deploy',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/ios-deploy',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:46:53',
npm ERR! 'FSReqWrap.oncomplete (fs.js:99:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/lixsys/app_view_android/npm-debug.log
There's a clue:
npm ERR! Please try running this command again as root/Administrator
Seems that you need to run the npm install as superuser:
$ sudo npm install -g ios-deploy
This is probably caused because npm was installed with restrictive permissions. To prevent that kind of issues on Mac it would be interesting for you to install npm through Node Version Manager so you won't require sudo permissions for that kind of things.

Resources