Docker中的Bcrypt安装失败

Ess*_*sso 4 bcrypt node.js docker

我创建了一个在Docker中运行的MongoDB节点应用程序.它工作正常,直到我包含node.bcrypt.js.这使得与节点崩溃node-gypbcrypt.

该应用程序在本地和Heroku上运行良好.

我尝试安装一些我在网上找到的建议包,根据错误消息已知需要这些包.这就是为什么我添加了一些额外的依赖项,请参阅node-gyp下面的dockerfile中的相关行.

现在它已经到了我找不到更多建议的地方,但它仍然无法正常工作.我觉得它在本地和Heorku上工作很奇怪,但在Docker上却没有,因此它是我所缺少的.

提前致谢.

错误:

> crowdshelf-server@1.0.0 start /server
> node index.js

  COPY Release/bcrypt_lib.node
make: Leaving directory `/server/node_modules/bcrypt/build'
module.js:338
    throw err;
          ^
Error: Cannot find module './lib/topologies/server'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/server/node_modules/mongodb/node_modules/mongodb-core/index.js:3:13)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)

npm ERR! Linux 3.13.0-58-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm ERR! node v0.12.7
npm ERR! npm  v2.11.3
npm ERR! code ELIFECYCLE
npm ERR! crowdshelf-server@1.0.0 start: `node index.js`
npm ERR! Exit status 1
Run Code Online (Sandbox Code Playgroud)

这是在我向Dockerfile添加了一些安装之后,请看之后的行node-gyp.Dockerfile:

# Base Docker-image on Ubuntu
FROM    ubuntu:latest

#install mongodb
#install git, curl, python and mongo
# node-gyp 
RUN apt-get install -y build-essential make automake gcc g++ cpp libkrb5-dev libc6-dev man-db autoconf pkg-config 

# Create the MongoDB data directory
RUN mkdir -p /data/db

# mongodb setup
# Install NodeJS
RUN curl --silent --location https://deb.nodesource.com/setup_0.12 | sudo bash -
RUN apt-get update && apt-get install -y nodejs
RUN npm install -g node-gyp

# Git-clone project
# expose ports
# Install dependencies and start server and database
CMD cd /server && sh start.sh
Run Code Online (Sandbox Code Playgroud)

starth.sh-script安装简单依赖关系和同时启动的MongoDB和服务器.

编辑:回购告诉我检查出节点GYP的依赖,但我觉得这就是被覆盖上面显示的Dockerfile.

Dav*_*tti 10

它正在崩溃,因为你缺少一些用于Bcrypt编译目的的基本工具.每次执行npm install操作系统的版本时都需要编译Bcrypt ,因为它是用C语言编写的.

对于那些想要使用原始Bcrypt的人,可以运行以下docker命令:

docker run -t -i --rm -v $(pwd):/app -w /app node:slim sh -c 'apt-get update && apt-get install -y build-essential && apt-get install -y python && npm install'
Run Code Online (Sandbox Code Playgroud)

在我们做之前,npm install我们需要:

  • apt-get update:确保包管理系统知道要找到我们想要的东西.
  • apt-get install -y build-essential:将安装编译C代码所需的所有工具等等
  • apt-get install -y python:我们添加了python,因为它是必需的,它不包含在build-essential包中.

一旦我们拥有所有这些东西,我们就可以npm install成功运行:)

希望这可以帮助.