Docker nodeJS bcrypt error - docker

I get following error when I try docker-compose up
graphql_1 | Error: Error loading shared library /usr/app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: Exec format error
graphql_1 | at Object.Module._extensions..node (internal/modules/cjs/loader.js:718:18)
graphql_1 | at Module.load (internal/modules/cjs/loader.js:599:32)
graphql_1 | at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
graphql_1 | at Function.Module._load (internal/modules/cjs/loader.js:530:3)
graphql_1 | at Module.require (internal/modules/cjs/loader.js:637:17)
graphql_1 | at require (internal/modules/cjs/helpers.js:20:18)
graphql_1 | at Object.<anonymous> (/usr/app/node_modules/bcrypt/bcrypt.js:6:16)
graphql_1 | at Module._compile (internal/modules/cjs/loader.js:689:30)
graphql_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
graphql_1 | at Module.load (internal/modules/cjs/loader.js:599:32)
graphql_1 | at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
graphql_1 | at Function.Module._load (internal/modules/cjs/loader.js:530:3)
graphql_1 | at Module.require (internal/modules/cjs/loader.js:637:17)
graphql_1 | at require (internal/modules/cjs/helpers.js:20:18)
graphql_1 | at Object.<anonymous> (/usr/app/src/REST/auth.js:1:78)
graphql_1 | at Module._compile (internal/modules/cjs/loader.js:689:30)
graphql_1 | npm ERR! code ELIFECYCLE
graphql_1 | npm ERR! errno 1
graphql_1 | npm ERR! project-eirene-whispr-graphql-server#1.0.0 start: `node server.js`
graphql_1 | npm ERR! Exit status 1
graphql_1 | npm ERR!
graphql_1 | npm ERR! Failed at the project-eirene-whispr-graphql-server#1.0.0 start script.
graphql_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
graphql_1 |
graphql_1 | npm ERR! A complete log of this run can be found in:
graphql_1 | npm ERR! /root/.npm/_logs/2018-08-15T10_36_46_244Z-debug.log
When I delete bcrypt module from package.json, docker-compose runs without a problem. I have seen a few posts on stack overflow suggesting to rebuild bcrypt after installing but this does not solve the problem.
My dockerfile setting is below
FROM node:10.8.0-alpine
# Whispr work directory
WORKDIR /usr/app
# Copy dependencies first for effective caching
COPY package*.json ./
RUN apk add --no-cache --virtual .build-deps alpine-sdk python \
&& npm install \
&& npm rebuild bcrypt --build-from-source \
&& apk del .build-deps
COPY . .
My docker-compose file is below
version: '3'
services:
redis:
image: redis:5.0-rc
postgresql:
image: postgres:10
env_file:
- postgresql.env
graphql:
build: .
command: npm run start
ports:
- "3000:3000"
volumes:
- .:/usr/app
env_file:
- .env
depends_on:
- "redis"
- "postgresql"
links:
- "redis"
- "postgresql"

I finally got it working by adding an anonymous volume for node_modules in my docker-compose.yml. You'll find more details in this article: https://www.richardkotze.com/top-tips/install-bcrypt-docker-image-exclude-host-node-modules
volumes:
- .:/usr/app # named volume
- /usr/app/node_modules # anonymous volume for node_modules only

I set up this on docker-compose and dockerfile, it working now
dockerfile:
RUN apk add --no-cache make gcc g++ python3 && \ npm install && \
npm rebuild bcrypt --build-from-source && \ apk del make gcc g++
python3
docker-compose:
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules

I have never managed to solve this in the end.
I ended up migrating the package to bcryptjs which does not require any OS specific dependencies.

Related

EACCES npm error in docker-compose cubejs container

I'm working on a docker-compose project. The goal is to get a database running, connected to a an angular app through cubejs. The idea is to use cube's dashboard maker for the angular app. I've been able to get both the database and cubejs running and connected them. However, when I try to create the dashboard app from cube's playground I get EACCES errors from npm. I'm pretty sure it's a docker issue because npm's proposed solution is to chown a folder named '.npm' which I don't know where to find.
I'm posting the console's output when trying to create the dashboard app, as well as my docker-compose.yml file below.
Console output
cube_1 | npm ERR! code EACCES
cube_1 | npm ERR! syscall mkdir
cube_1 | npm ERR! path /.npm
cube_1 | npm ERR! errno -13
cube_1 | npm ERR!
cube_1 | npm ERR! Your cache folder contains root-owned files, due to a bug in
cube_1 | npm ERR! previous versions of npm which has since been addressed.
cube_1 | npm ERR!
cube_1 | npm ERR! To permanently fix this problem, please run:
cube_1 | npm ERR! sudo chown -R 1002:1002 "/.npm"
cube_1 | npm ERR! code EACCES
cube_1 | npm ERR! syscall mkdir
cube_1 | npm ERR! path /.npm
cube_1 | npm ERR! errno -13
cube_1 | npm ERR!
cube_1 | npm ERR! Your cache folder contains root-owned files, due to a bug in
cube_1 | npm ERR! previous versions of npm which has since been addressed.
cube_1 | npm ERR!
cube_1 | npm ERR! To permanently fix this problem, please run:
cube_1 | npm ERR! sudo chown -R 1002:1002 "/.npm"
cube_1 | npm ERR! code EACCES
cube_1 | npm ERR! syscall mkdir
cube_1 | npm ERR! path /.npm
cube_1 | npm ERR! errno -13
cube_1 | npm ERR!
cube_1 | npm ERR! Your cache folder contains root-owned files, due to a bug in
cube_1 | npm ERR! previous versions of npm which has since been addressed.
cube_1 | npm ERR!
cube_1 | npm ERR! To permanently fix this problem, please run:
cube_1 | npm ERR! sudo chown -R 1002:1002 "/.npm"
cube_1 | npm ERR! code EACCES
cube_1 | npm ERR! syscall mkdir
cube_1 | npm ERR! path /.npm
cube_1 | npm ERR! errno -13
cube_1 | npm ERR!
cube_1 | npm ERR! Your cache folder contains root-owned files, due to a bug in
cube_1 | npm ERR! previous versions of npm which has since been addressed.
cube_1 | npm ERR!
cube_1 | npm ERR! To permanently fix this problem, please run:
cube_1 | npm ERR! sudo chown -R 1002:1002 "/.npm"
cube_1 | npm ERR! code EACCES
cube_1 | npm ERR! syscall mkdir
cube_1 | npm ERR! path /.npm
cube_1 | npm ERR! errno -13
cube_1 | npm ERR!
cube_1 | npm ERR! Your cache folder contains root-owned files, due to a bug in
cube_1 | npm ERR! previous versions of npm which has since been addressed.
cube_1 | npm ERR!
cube_1 | npm ERR! To permanently fix this problem, please run:
cube_1 | npm ERR! sudo chown -R 1002:1002 "/.npm"
cube_1 | npm ERR! code EACCES
cube_1 | npm ERR! syscall mkdir
cube_1 | npm ERR! path /.npm
cube_1 | npm ERR! errno -13
cube_1 | npm ERR!
cube_1 | npm ERR! Your cache folder contains root-owned files, due to a bug in
cube_1 | npm ERR! previous versions of npm which has since been addressed.
cube_1 | npm ERR!
cube_1 | npm ERR! To permanently fix this problem, please run:
cube_1 | npm ERR! sudo chown -R 1002:1002 "/.npm"
cube_1 | npm ERR! code EACCES
cube_1 | npm ERR! syscall mkdir
cube_1 | npm ERR! path /.npm
cube_1 | npm ERR! errno -13
cube_1 | npm ERR!
cube_1 | npm ERR! Your cache folder contains root-owned files, due to a bug in
cube_1 | npm ERR! previous versions of npm which has since been addressed.
cube_1 | npm ERR!
cube_1 | npm ERR! To permanently fix this problem, please run:
cube_1 | npm ERR! sudo chown -R 1002:1002 "/.npm"
cube_1 | npm ERR! code EACCES
cube_1 | npm ERR! syscall mkdir
cube_1 | npm ERR! path /.npm
cube_1 | npm ERR! errno -13
cube_1 | npm ERR!
cube_1 | npm ERR! Your cache folder contains root-owned files, due to a bug in
cube_1 | npm ERR! previous versions of npm which has since been addressed.
cube_1 | npm ERR!
cube_1 | npm ERR! To permanently fix this problem, please run:
cube_1 | npm ERR! sudo chown -R 1002:1002 "/.npm"
cube_1 | npm ERR! code EACCES
cube_1 | npm ERR! syscall mkdir
cube_1 | npm ERR! path /.npm
cube_1 | npm ERR! errno -13
cube_1 | npm ERR!
cube_1 | npm ERR! Your cache folder contains root-owned files, due to a bug in
cube_1 | npm ERR! previous versions of npm which has since been addressed.
cube_1 | npm ERR!
cube_1 | npm ERR! To permanently fix this problem, please run:
cube_1 | npm ERR! sudo chown -R 1002:1002 "/.npm"
cube_1 | npm ERR! code EACCES
cube_1 | npm ERR! syscall mkdir
cube_1 | npm ERR! path /.npm
cube_1 | npm ERR! errno -13
cube_1 | npm ERR!
cube_1 | npm ERR! Your cache folder contains root-owned files, due to a bug in
cube_1 | npm ERR! previous versions of npm which has since been addressed.
cube_1 | npm ERR!
cube_1 | npm ERR! To permanently fix this problem, please run:
cube_1 | npm ERR! sudo chown -R 1002:1002 "/.npm"
cube_1 | Error: npm install failed with exit code 243. Please check your console.
cube_1 | at ChildProcess.<anonymous> (/cube/node_modules/#cubejs-backend/shared/src/helpers.ts:29:11)
cube_1 | at ChildProcess.emit (events.js:400:28)
cube_1 | at maybeClose (internal/child_process.js:1088:16)
cube_1 | at Process.ChildProcess._handle.onexit (internal/child_process.js:296:5)
docker-compose.yml
version: '2.2'
services:
clickhouse_server:
user: "${UID}:${GID}"
image: clickhouse/clickhouse-server
ports:
- "8123:8123"
volumes:
- ./db:/var/lib/clickhouse
cube:
user: "${UID}:${GID}"
image: cubejs/cube
# ignored because of network_mode
# ports:
# - 3000:3000
# - 4000:4000
env_file: .env
volumes:
- .:/cube/conf
- .empty:/cube/conf/node_modules/#cubejs-backend/
depends_on:
- clickhouse_server
network_mode: "host" # may be linux specific
I've tried adding a volume for cubejs node_modules folder, which didn't work. I've also tried running docker-compose exec cube npm install --save #cubejs-client/ngx which prints the same EACCES errors the dashboard app maker does, and docker-compose exec cube npm update which prints
┌──────────────────────────────────────────────┐
│ npm update check failed │
│ Try running with sudo or get access │
│ to the local update config store via │
│ sudo chown -R $USER:$(id -gn $USER) /.config │
└──────────────────────────────────────────────┘
I'm working on Debian 11 in case it matters.
Also, cubejs image's node and npm versions are 14.21.1 and 6.14.17 respectively.

I get "permission denied" when docker run the npm run serve command

This is my Dockerfile:
FROM node:alpine
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package*.json .
RUN npm install #vue/cli#5.0.8 -g
RUN npm install
CMD ["npm", "run", "serve"]
I use node alpine well and I already tried chmod 777 or npm config set unsafe-perm true but nothing works...
and this is my docker-compose:
version: '3.9'
services:
frontend:
build: ./services/frontend
volumes:
- './services/frontend:/app'
- '/app/node_modules'
ports:
- 8080:8080
here is the error I get when I run sudo docker compose up --build:
fastapi-vue-frontend-1 |
fastapi-vue-frontend-1 | > frontend#0.1.0 serve
fastapi-vue-frontend-1 | > vue-cli-service serve
fastapi-vue-frontend-1 |
fastapi-vue-frontend-1 | INFO Starting development server...
ERROR Failed to compile with 1 error11:24:09 AM
fastapi-vue-frontend-1 |
fastapi-vue-frontend-1 | error in ./node_modules/events/events.js
fastapi-vue-frontend-1 |
fastapi-vue-frontend-1 | Syntax Error: Error: EACCES: permission denied, mkdir '/app/node_modules/.cache'
fastapi-vue-frontend-1 |
fastapi-vue-frontend-1 |
ERROR in ./node_modules/events/events.js
fastapi-vue-frontend-1 | Module build failed (from ./node_modules/babel-loader/lib/index.js):
fastapi-vue-frontend-1 | Error: EACCES: permission denied, mkdir '/app/node_modules/.cache'
fastapi-vue-frontend-1 | # ./node_modules/webpack/hot/emitter.js 1:19-36
fastapi-vue-frontend-1 | # ./node_modules/webpack/hot/dev-server.js 50:18-38
fastapi-vue-frontend-1 |
fastapi-vue-frontend-1 | ERROR in ./node_modules/webpack-dev-server/client/index.js?protocol=auto%3A&username=&password=&hostname=0.0.0.0&port=0&pathname=%2Fws&logging=none&progress=true&overlay=%7B%22errors%22%3Atrue%2C%22warnings%22%3Afalse%7D&reconnect=10&hot=true&live-reload=true
fastapi-vue-frontend-1 | Module build failed (from ./node_modules/babel-loader/lib/index.js):
fastapi-vue-frontend-1 | Error: EACCES: permission denied, mkdir '/app/node_modules/.cache'
fastapi-vue-frontend-1 |
fastapi-vue-frontend-1 | ERROR in ./src/main.js
fastapi-vue-frontend-1 | Module build failed (from ./node_modules/babel-loader/lib/index.js):
fastapi-vue-frontend-1 | Error: EACCES: permission denied, mkdir '/app/node_modules/.cache'
fastapi-vue-frontend-1 |
fastapi-vue-frontend-1 | ERROR in [eslint] EACCES: permission denied, mkdir '/app/node_modules/.cache/eslint'
fastapi-vue-frontend-1 |
fastapi-vue-frontend-1 | webpack compiled with 4 errors
what I don't understand is that it doesn't affect all the files but only the .cache folder (is it because of the hidden folder??)

No such file or directory npm error in docker-compose up command

I am almost new to docker-compose. I need to create a yml file, for creating and configuring my container, but I faced a npm error related when trying to run a container from my image.
I already have a container running, having these content:
node#7b822f0c11d8:/usr/src/osjs$ ls
CONTRIBUTING.md LICENSE dist entrypoint.sh package-lock.json packages.json src webpack.config.js
Dockerfile README.md docker-compose.yml node_modules package.json session-store.db vfs
I have created an image from my container by using docker commit command.
Here is my image:
REPOSITORY TAG IMAGE ID CREATED SIZE
hafez/hafez version1.1 528fd0061a33 4 seconds ago 923MB
I put my yml and config files in myDirectory. Here is the output of ls in myDirectory:
config1.js config2.js my-docker-compose.yml
This is the my-docker-compose.yml content:
version: "3"
services:
hafez:
image: hafez/hafez:version1.1
restart: always
container_name: hafez
ports:
- 8000:8000
volumes:
- ./config1.js:/usr/src/osjs/src/client/config.js
- ./config2.js:/usr/src/osjs/src/server/config.js
And here is the output of docker-compose -f my-docker-compose.yml up:
Creating hafez ... done
Attaching to hafez
hafez | npm WARN saveError ENOENT: no such file or directory, open '/usr/src/osjs/package.json'
hafez | npm WARN saveError EACCES: permission denied, open '/usr/src/osjs/package-lock.json.1134850457'
hafez | npm WARN enoent ENOENT: no such file or directory, open '/usr/src/osjs/package.json'
hafez | npm WARN osjs No description
hafez | npm WARN osjs No repository field.
hafez | npm WARN osjs No README data
hafez | npm WARN osjs No license field.
hafez |
hafez | up to date in 1.506s
hafez | found 0 vulnerabilities
hafez |
hafez | npm ERR! code ENOENT
hafez | npm ERR! syscall open
hafez | npm ERR! path /usr/src/osjs/package.json
hafez | npm ERR! errno -2
hafez | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/osjs/package.json'
hafez | npm ERR! enoent This is related to npm not being able to find a file.
hafez | npm ERR! enoent
hafez |
hafez | npm ERR! A complete log of this run can be found in:
hafez | npm ERR! /home/node/.npm/_logs/2021-09-17T11_15_37_791Z-debug.log
hafez | npm ERR! code ENOENT
hafez | npm ERR! syscall open
hafez | npm ERR! path /usr/src/osjs/package.json
hafez | npm ERR! errno -2
hafez | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/osjs/package.json'
hafez | npm ERR! enoent This is related to npm not being able to find a file.
hafez | npm ERR! enoent
hafez |
hafez | npm ERR! A complete log of this run can be found in:
hafez | npm ERR! /home/node/.npm/_logs/2021-09-17T11_15_38_196Z-debug.log
hafez | Usage: nodemon [nodemon options] [script.js] [args]
hafez |
hafez | See "nodemon --help" for more.
hafez |
How can I fix this error and create/config container successfully?

Docker permission issues with Yarn

I'm having the following issue when trying run my container:
psa-web | Error: EACCES: permission denied, open '/root/.config/yarn'
psa-web | at Object.openSync (node:fs:495:3)
psa-web | at readFileSync (node:fs:396:35)
psa-web | at /opt/yarn-v1.22.5/lib/cli.js:101332:58
psa-web | at Array.map (<anonymous>)
psa-web | at parseRcPaths (/opt/yarn-v1.22.5/lib/cli.js:101330:78)
psa-web | at Object.findRc (/opt/yarn-v1.22.5/lib/cli.js:101344:10)
psa-web | at getRcConfigForCwd (/opt/yarn-v1.22.5/lib/cli.js:56916:74)
psa-web | at /opt/yarn-v1.22.5/lib/cli.js:92695:56
psa-web | at Generator.next (<anonymous>)
psa-web | at step (/opt/yarn-v1.22.5/lib/cli.js:310:30)
psa-web | npm ERR! code 1
psa-web | npm ERR! path /usr/src/app
psa-web | npm ERR! command failed
psa-web | npm ERR! command sh -c yarn install && next dev
psa-web |
psa-web | npm ERR! A complete log of this run can be found in:
psa-web | npm ERR! /root/.npm/_logs/2021-01-29T09_01_06_202Z-debug.log
version: "3"
services:
psa-web:
build:
context: .
dockerfile: Dockerfile
container_name: psa-web
restart: always
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
- /usr/src/app/.next
ports:
- "${NEXT_PUBLIC_APP_PORT}:${NEXT_PUBLIC_APP_PORT}"
Here's my Dockerfile:
FROM node:15.5.0-alpine3.10
RUN apk add --update --no-cache \
python \
make \
g++
WORKDIR /usr/src/app
# install and cache app dependencies
COPY package.json /usr/src/app
COPY yarn.lock /usr/src/app
RUN yarn install --frozen-lockfile
EXPOSE 3003
CMD ["npm", "run", "dev"]
Here's also the package.json file, for better context. That's were I automatically run yarn install before starting my next application on dev, and the potential source of this error.
package.json
"scripts": {
"dev": "yarn install && next dev",
"build": "next build",
"start": "yarn install && next start",
"lint": "eslint .",
"update:shared-deps": "yarn upgrade --scope #project-stock-alarm --latest",
"lint:fix": "eslint . --fix"
},
Any ideas of what I'm doing wrong?
If I do a sudo yarn install and a sudo chown -R root it solves the issue, but this is not best practice.

permission denied in Dockerfile

Trying to build my dockerfile, and getting a permission denied error.
The project is a nest.js server. Here is the dockerfile:
FROM node:12.13-alpine
WORKDIR /usr/src/app
COPY package.json .
RUN npm install <<< this fails
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "run", "start:prod"]
and the error (on npm install) is:
internal/fs/utils.js:220
throw err;
^
Error: EACCES: permission denied, open '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
at Object.openSync (fs.js:440:3)
at Object.readFileSync (fs.js:342:35)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:994:22)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11 {
errno: -13,
syscall: 'open',
code: 'EACCES',
path: '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
Any idea?
Solved. the solution was in 2 steps:
re-install docker.
changing owner to node, like this:
FROM node:10
RUN mkdir -p /home/node/app && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY package.json .
USER node
RUN npm install
...

Resources