Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

877
Visualizações
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

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

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"]
about 4 years ago · Santiago Trujillo Relatório

0

was struggling with this one few times, the ".dockerignore" solution wont work if you use volumes sadly, since its only related to the "Copy" command and only when you build the container.

the only solution i found which i think makes the most sense, is to volume only what you need, what does it mean - divide your source code and the "configurations" files (such as package.json):

- src
-- morecode
-- morecode2
-- server.js
- index.js
- package.json
- jslint.json
- tsconfig.json
- .env
- .dockerignore
- ... etc

and put the volume only on the "src" folder, that way your builds will also be much faster plus your node modules will be built and installed on the correct operation system, d'ont forget to add .dockerignore to node_modules to prevent builds form taking unnecessary longer time

do note that doing so will require re-build of the application every time your adding new package, but if you use npm best practice and you divide the npm installation in your docker file to be cached, it will be faster

about 4 years ago · Santiago Trujillo Relatório

0

The reason this error occurs is that the node module bcrypt is first compiled on your original machine (specific for your OS) and when an image is built on docker it cannot run since the OS is no longer the same. solution create a .dockerignore file in your root folder and add node_modules to this file.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda