6

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! [email protected] start: `node server.js`
graphql_1     | npm ERR! Exit status 1
graphql_1     | npm ERR! 
graphql_1     | npm ERR! Failed at the [email protected] 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"

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

-1

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.

1 Comment

bcryptjs gives me the same issue... what am I missing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.