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 thedocker-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
withbcryptjs
package and then runningnpm 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
tobcryptjs
. It works for me on Mac M1 – Iago Leão Commented Feb 1, 2022 at 18:48
1 Answer
Reset to default 5For 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.