3

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  <james@claridgeand.co>

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
James Claridge
  • 179
  • 1
  • 11

2 Answers2

7

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).

nijm
  • 2,158
  • 12
  • 28
2

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  <james@claridgeand.co>

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
Alejandro Galera
  • 3,445
  • 3
  • 24
  • 42
  • 1
    Still not working but I'm a step closer now - now its stuck on api_1 | NODE_MODULE_VERSION 57. This version of Node.js requires api_1 | NODE_MODULE_VERSION 59. Please try re-compiling or re-installing despite having an uptodate npm version – James Claridge Jul 04 '18 at 09:20
  • I think I've found solution. If you change in your Dockerfile `alpine-node` version from 9.1.0 to 10.5.0 it works (latest): `FROM mhart/alpine-node:latest`, but adding `RUN apk update`. See latest version in https://hub.docker.com/r/mhart/alpine-node/ – Alejandro Galera Jul 04 '18 at 09:26
  • 1
    For `FROM node:16.13-alpine3.15` run command should be like: `RUN apk --no-cache add --virtual .builds-deps build-base python3` – MadaShindeInai Jan 26 '22 at 12:22