Bcrypt installation fails in Docker

只愿长相守 提交于 2019-12-05 15:55:54

It is crashing because you are missing some essentials tool for the compilation purposes of Bcrypt. Bcrypt needs to be compiled each time you do npm install to crate a version for the operating system that is running on since it is written in C.

For those that would like to use the original Bcrypt, you can run the following docker command:

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'

Before we do npm install we need to:

  • apt-get update: make sure the package management system knows were to find what we want.
  • apt-get install -y build-essential: will install all the tools needed to compile C code and more
  • apt-get install -y python: we add python since it is needed and it is not included in the build-essential package.

Once we have all this stuff, we can run npm install successfully :)

Hope this helps.

I solved this by simply changing the bcrypt-library. This one was created based on a similar problem, and provides the same API. The only difference from the library mentioned in my question is:

bcrypt.hash(password, function(err, hash) {
    if(!err) callback(hash);
});

While in the one linked in this answer:

bcrypt.hash(password, null, null, function(err, hash) { // Addd nulls
    if(!err) callback(hash);
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!