James Claridge
James Claridge

Reputation: 188

BCRYPT - Build from source on Alpine:node and causes segfaults using this docker file when its used

Build this docker file and try and use Bcrypt to complete a hash and it will segfault, and I can't figure out why for the life of me.

FROM mhart/alpine-node:9.1.0

MAINTAINER James Claridge  <[email protected]>

RUN mkdir /app
WORKDIR /app
RUN apk --no-cache add --virtual builds-deps build-base python
RUN npm config set python /usr/bin/python
RUN npm i -g npm
RUN npm install
RUN npm rebuild bcrypt --build-from-source
RUN apk del builds-deps

Upvotes: 3

Views: 11162

Answers (2)

nijm
nijm

Reputation: 2218

Use bcryptjs, it doesn't require you to install additional dependencies and rebuild from source. See https://www.npmjs.com/package/bcryptjs

If you really want to use the bcrypt, see their issue on github and their instructions. There are some workaround there, but this will require some additional dependency installing. The easiest way to keep using bcrypt would be to not use the alpine version, but the ubuntu version of node (with its additional overhead).

Upvotes: 7

Alejandro Galera
Alejandro Galera

Reputation: 3691

The problem is that you're trying to install a npm version that has a bug. In your installation, RUN npm install doesn't work, so, rebuild bcrypt crashes.

After that, you should add before npm install some commands like explained in these links:

error-cannot-find-module-npmlog-after-npm-update-g

Issue npm version 5.4.1 solved upgrading to 6.1.0

EDIT: It's an issue related to alpine-node version available packages:

Use this Dockerfile:

FROM mhart/alpine-node:latest 

MAINTAINER James Claridge  <[email protected]>

RUN apk update
RUN mkdir /app
WORKDIR /app
RUN apk --no-cache add --virtual builds-deps build-base python
RUN npm config set python /usr/bin/python
RUN npm i -g npm
RUN npm install
RUN npm rebuild bcrypt --build-from-source
RUN apk del builds-deps

Upvotes: 2

Related Questions