最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to deal with Exec format error in docker-compose - Stack Overflow

programmeradmin3浏览0评论

I tried to build server and db through docker

Here is my docker-pose.yml

version: '3'

services:
  api-server:
    build: ./api
    links:
      - 'db'
    ports:
      - '3000:3000'
    volumes:
      - ./api:/src
      - ./src/node_modules
    tty: true
    container_name: api-server

  db:
    build:
      context: .
      dockerfile: ./db/Dockerfile
    restart: always
    hostname: db
    environment:
      MYSQL_ROOT_PASSWORD: test
      MYSQL_USER: root
      MYSQL_PASSWORD: test
      MYSQL_DATABASE: db
    volumes:
      - './db:/config'
    ports:
      - 3306:3306
    container_name: db

Here is my Dockerfile

FROM node:alpine

WORKDIR /src
COPY . .

RUN rm -rf /src/node_modules
RUN rm -rf /src/package-lock.json

RUN yarn install

CMD yarn start:dev

After set up servers,I tried to access. but following error occured

Error: Error loading shared library /src/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: Exec format error

I wonder where is the problem. And How to fix it.

If someone has opinion,please let me know.

Thanks

I tried to build server and db through docker

Here is my docker-pose.yml

version: '3'

services:
  api-server:
    build: ./api
    links:
      - 'db'
    ports:
      - '3000:3000'
    volumes:
      - ./api:/src
      - ./src/node_modules
    tty: true
    container_name: api-server

  db:
    build:
      context: .
      dockerfile: ./db/Dockerfile
    restart: always
    hostname: db
    environment:
      MYSQL_ROOT_PASSWORD: test
      MYSQL_USER: root
      MYSQL_PASSWORD: test
      MYSQL_DATABASE: db
    volumes:
      - './db:/config'
    ports:
      - 3306:3306
    container_name: db

Here is my Dockerfile

FROM node:alpine

WORKDIR /src
COPY . .

RUN rm -rf /src/node_modules
RUN rm -rf /src/package-lock.json

RUN yarn install

CMD yarn start:dev

After set up servers,I tried to access. but following error occured

Error: Error loading shared library /src/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: Exec format error

I wonder where is the problem. And How to fix it.

If someone has opinion,please let me know.

Thanks

Share Improve this question asked Sep 19, 2020 at 1:49 HeisenbergHeisenberg 5,30915 gold badges58 silver badges99 bronze badges 4
  • Does deleting the volumes: in the docker-pose.yml file help? Or equivalently, docker-pose down -v? – David Maze Commented Sep 19, 2020 at 11:35
  • this seems to be because bcrypt build for you machine (mac os?) is not able to work on the docker image (linux) stackoverflow./a/20590261/2422826 for me, I tried several approaches to try to get docker to pile it's own bcrypt including richardkotze./top-tips/…; however, it didn't work even making sure I had a .dockerignore file and making sure everything was removed...I did get it to work by replacing bcrypt with bcryptjs package and then running npm rebuild. I would love to see better steps to solve this. – auerbachb Commented Nov 3, 2020 at 0:31
  • I am in the same boat as auerbachb, I have tried everything and can't get it to work – foba Commented Feb 11, 2021 at 0:22
  • 2 Replace bcrypt to bcryptjs. It works for me on Mac M1 – Iago Leão Commented Feb 1, 2022 at 18:48
Add a ment  | 

1 Answer 1

Reset to default 5

For everybody looking for an solution like me, the solution for me was adding a .dockerignore file with the following content:

.dockerignore
node_modules

My Dockerfile looks like this:

FROM node:14-alpine as development
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

Adding the .dockerignore-file prevents the COPY . .-mand from copying the node_modules-folder and fixes the issue with bcrypt not loading.

发布评论

评论列表(0)

  1. 暂无评论