Node.bcrypt.js: invalid ELF header when I use it on docker

Created on 13 Feb 2018  路  6Comments  路  Source: kelektiv/node.bcrypt.js

FROM node:carbon

RUN npm install nodemon -g
WORKDIR /app
COPY . /app
RUN npm install

EXPOSE 3030

CMD [ "npm","start" ]

CMD [ "npm" , "run" ,"dev" ]

Most helpful comment

This looks like you are copying the node_modules from your local, which is probably not Linux.

Add a .dockerignore excluding node_modules

Feel free to reopen, if issue persists.

All 6 comments

This looks like you are copying the node_modules from your local, which is probably not Linux.

Add a .dockerignore excluding node_modules

Feel free to reopen, if issue persists.

Hello, I'm had the same problem :(

I have the same error.
I have node version v12.13.1
bcrypt version: "3.0.7"

Dockerfile:

FROM node:12.13.1
WORKDIR /server
COPY . .
RUN npm install
EXPOSE 8000
CMD ["npm", "run", "dev"]

docker-compose.yml

version: "3.3"
services:
  db:
    build: ./db
    restart: always
    env_file:
      - ./.env
    ports:
      - 3306:3306
    networks:
      - app_network
  server:
    depends_on:
      - "db" # this is important for sql connection. it has to wait for mysql to establish connection then run this bish
    build: .
    command: ["npm", "run", "dev"]
    restart: always
    ports:
      - "8000:8000"
    volumes:
      - type: bind
        source: .
        target: /server # this name is from dockerfile workdir
    networks:
      - app_network

networks:
  app_network:
volumes:
  app_volume:

dockerignore file:

.env
.vscode

did you resolve this issue? @JulianeAlbuquerque @lagmanzaza

@lagmanzaza yes thank you! Ive done something but different link. thanks man

The root cause is => Docker Context. Docker context is copying everything from your root folder to destination container working directory.

So your node_modules (& loading mechanism as per your host OS) is also copied to container working directory.

So you have to add a .dockerignore file and add these entries (with any other files that you want to ignore)

  • node_modules
  • npm-debug.log

And now when you will build your container, it will build everything as per container's OS and you will not get invalid ELF header error

Was this page helpful?
0 / 5 - 0 ratings