尝试时出现以下错误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"