Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker with node bcrypt — invalid ELF header

I've tried every solution from this post and this post

I'm not finding a solution to get rid of the following error when running docker-compose up:

module.js:598
  return process.dlopen(module, path._makeLong(filename));
                 ^

Error: /code/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header

Here's my latest attempt docker-compose.yml

version: "2"

services:
  app:
    build: ./client
    ports:
      - "3000:3000"
    links:
      - auth
    volumes:
      - ./client:/code
  auth:
    build: ./auth-service
    ports:
      - "3002:3002"
    links:
      - db
    volumes:
      - ./auth-service:/code
  db:
    ...

And my auth service Dockerfile:

FROM node:7.7.1

EXPOSE 3002

WORKDIR /code

COPY package.json /code

RUN npm install

COPY . /code

CMD npm start

After trying each of the solution from the above two links, I rebuild the containers and it always results in the same error.

Also worth noting, the service runs fine locally, when I don't use docker.

How do I get docker to work with bcrypt?

Update

I was able to get it working by doing the following:

  1. finding the id of the container: docker ps
  2. accessing the container: docker exec -t -i containerId /bin/bash
  3. installing bcrypt: npm install bcrypt

This isn't ideal for portability

like image 566
Scott Avatar asked Mar 15 '17 18:03

Scott


1 Answers

I spent a few hours trying to solve this and in the end I came up with the following solution. My compose file looks like this.....

version: "3"

services:
  server:
    build:
      context: ./server
    volumes:
     - ./server:/usr/src/app
     - /usr/src/app/node_modules/
    ports:
      - 3050:3050
    depends_on:
  - db
command: ["nodemon", "./bin/www"]

The second volume mount there is the important one as this gets around the local node_module issue.

Just for reference my dockerfile is like this:

FROM node
RUN npm install -g nodemon
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
EXPOSE 3050
CMD ["nodemon", "./bin/www"]
like image 99
Intellidroid Avatar answered Oct 06 '22 16:10

Intellidroid