Search code examples
dockerdocker-composenode-modulesbcrypt

Docker Failed - bcrypt_lib.node: Exec format error


I have tried to create a docker image of my backend API. but getting errors. I have googled about it, and everyone who has the same issue had to add node_module on the .dockerignore file.

I already did it, but, still have the same error.

I am adding my file info here.

Dockerfile

FROM node:alpine
WORKDIR /usr/src/app
COPY package*.json .
#COPY yarn.lock .
RUN apk add --no-cache yarn --repository="http://dl-cdn.alpinelinux.org/alpine/edge/community"
#RUN yarn install --frozen-lockfile
RUN yarn install
RUN yarn
COPY . .
CMD ["yarn", "dev"];

.dockerignore

/node_modules
.env
docker-compose.yml

docker-compose.yml

version: "3.9"

services:
  mongo_db:
    container_name: mongodb_container
    image: mongo:latest
    restart: always
    ports:
      - "27017:27017"
    volumes:
      - mongo_db:/data/db

  #EET service
  eetapi:
    container_name: eetapi_container
    build: .
    volumes:
      - .:/usr/src/app
    ports:
      - "3000:3000"
    environment:
      SITE_URL: http://localhost
      PORT: 3000
      MONGO_URL: mongodb://mongodb_container:27017/easyetapi
      JWT_SECRET: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      SENTRY_DSN: https://[email protected]/xxxxxxx
      MAILGUN_DOMAIN: mg.myeetdomain.tld
      MAILGUN_API_KEY: xxxxxxxxxxxxxxx-xxxxxxxxxxx-xxxxxxxx
      NODE_ENV: production
    depends_on:
      - mongo_db
volumes:
  mongo_db: {}

The Error

Error Screenshot

Please help me out.

Thank You


Solution

  • The volumes: block overwrites everything in the image with the current directory on the host. That includes the node_modules tree installed in the Dockerfile. If you have a MacOS or Windows host but a Linux container, replacing the node_modules tree will cause the error you get.

    You should delete the volumes: block so that you run the code and library tree that are built into the image.

    Since the bind-mount overwrites literally everything the Dockerfile does, it negates any benefit you get from building the Docker image. Effectively you're just running an unmodified node image with bind-mounted host content, and you'll get the same effect with a much simpler setup if you Node on the host without involving Docker. (You could still benefit from running the database in a container.)