[英]Running Docker on Ubuntu 18.04 getting error [/bin/sh 1] [:missing] when trying sudo docker-compose up
[英]/bin/sh: sequelize: not found when I try to run express.js app with docker-compose
我在用戶服務目錄的 Dockerfile 中有這個。
FROM node:15-alpine
COPY . /app
WORKDIR /app
RUN echo ">>>> $PWD"
RUN ls -lart
RUN yarn install
RUN ls -lart /app/node_modules/.bin
CMD yarn watch
當前目錄是預期的/app
。 Sequelize 二進制文件位於node_modules/.bin
文件夾中。 /app/node_modules/.bin
命令的結果是...
total 16
lrwxrwxrwx 1 root root 21 Apr 9 18:35 uuid -> ../uuid/dist/bin/uuid
lrwxrwxrwx 1 root root 30 Apr 9 18:35 sequelize-cli -> ../sequelize-cli/lib/sequelize
lrwxrwxrwx 1 root root 30 Apr 9 18:35 sequelize -> ../sequelize-cli/lib/sequelize
這是docker-compose.yml
:
....
services:
users-service:
build: './users-service'
depends_on:
- users-service-db
environment:
- DB_URI=mysql://root:**********@users-service-db/users_db?charset=UTF8
ports:
- 7100:7100
volumes:
- ./users-service:/app
networks:
- autostop
users-service-db:
command: --default-authentication-plugin=mysql_native_password
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=users_db
restart: always
image: mysql:5.7.20
ports:
- 0.0.0.0:3306:3306
networks:
- autostop
...
當我運行docker-compose build
或docker-compose up --build
它顯示
$ yarn db:migrate && babel-watch -L src/index.js
users-service_1 | $ sequelize db:migrate
users-service_1 | /bin/sh: sequelize: not found
問題是,當您 map 卷時,即使是node_modules
被主機文件夾覆蓋。 如果主機源代碼中沒有node_modules
,它將無法工作。 所以你想要的是屏蔽容器的node_modules
文件夾,這樣它就不會受到主機文件夾 map 的影響
....
services:
users-service:
build: './users-service'
depends_on:
- users-service-db
environment:
- DB_URI=mysql://root:**********@users-service-db/users_db?charset=UTF8
ports:
- 7100:7100
volumes:
- ./users-service:/app
- node_modules:/app/node_modules
networks:
- autostop
users-service-db:
command: --default-authentication-plugin=mysql_native_password
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=users_db
restart: always
image: mysql:5.7.20
ports:
- 0.0.0.0:3306:3306
networks:
- autostop
volumes:
node_modules:
...
通過將其映射到命名卷,將確保內部文件夾不受外部主機映射文件夾的影響
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.