Docker nodeJS bcrypt错误

时间:2018-08-15 10:39:29

标签: docker

尝试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

当我从package.json删除bcrypt模块时,docker-compose运行没有问题。我在堆栈溢出中看到了一些建议安装后重建bcrypt的帖子,但这不能解决问题。

我的dockerfile设置低于

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 . .

我的docker-compose文件在下面

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"

2 个答案:

答案 0 :(得分:0)

通过在我的 node_modules 中为 docker-compose.yml 添加一个匿名卷,我终于让它工作了。您将在本文中找到更多详细信息: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

答案 1 :(得分:-1)

我从来没有设法解决这个问题。

我最终将软件包迁移到bcryptjs,不需要任何特定于操作系统的依赖项。