gpt4 book ai didi

Docker NodeJS bcrypt 错误

转载 作者:行者123 更新时间:2023-12-03 02:32:49 24 4
gpt4 key购买 nike

当我尝试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"

最佳答案

我终于通过在 docker-compose.yml 中添加 node_modules 的匿名卷来使其正常工作。您将在本文中找到更多详细信息: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

关于Docker NodeJS bcrypt 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51857188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com