尝试使用docker compose使用mariadb运行我的nestjs应用程序
这是我的dockerfile
FROM node:18-alpine
WORKDIR /user/src/app
COPY . .
RUN npm ci --omit=dev
RUN npm run build
USER node
CMD ["npm", "run", "start:prod"]
关于dockercomposite.yml
version: '3.5'
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- '3000:3000'
depends_on:
- database
env_file:
- .env
volumes:
- ./src:/app/src
database:
image: mariadb:10.6
restart: always
container_name: MARIADB
networks:
- mariadb
env_file:
- docker.env
volumes:
- ./mariadb_data:/var/lib/mysql
ports:
- '3306:3306'
networks:
mariadb:
driver: bridge
我得到以下错误
ecommerce-backend-app-1 |
ecommerce-backend-app-1 | > [email protected] start /usr/src/app
ecommerce-backend-app-1 | > node dist/main
ecommerce-backend-app-1 |
ecommerce-backend-app-1 |
ecommerce-backend-app-1 | internal/modules/cjs/loader.js:934
ecommerce-backend-app-1 | throw err;
ecommerce-backend-app-1 | ^
ecommerce-backend-app-1 |
ecommerce-backend-app-1 | Error: Cannot find module '/usr/src/app/dist/main'
ecommerce-backend-app-1 | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:931:15)
ecommerce-backend-app-1 | at Function.Module._load (internal/modules/cjs/loader.js:774:27)
ecommerce-backend-app-1 | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
ecommerce-backend-app-1 | at internal/main/run_main_module.js:17:47 {
ecommerce-backend-app-1 | code: 'MODULE_NOT_FOUND',
ecommerce-backend-app-1 | requireStack: []
ecommerce-backend-app-1 | }
ecommerce-backend-app-1 |
ecommerce-backend-app-1 | npm
ecommerce-backend-app-1 | ERR!
ecommerce-backend-app-1 | code
ecommerce-backend-app-1 | ELIFECYCLE
ecommerce-backend-app-1 | npm ERR! errno 1
ecommerce-backend-app-1 | npm ERR! [email protected] start: `node dist/main`
ecommerce-backend-app-1 | npm
ecommerce-backend-app-1 | ERR!
ecommerce-backend-app-1 | Exit status 1
ecommerce-backend-app-1 | npm
ecommerce-backend-app-1 | ERR!
ecommerce-backend-app-1 |
ecommerce-backend-app-1 | npm ERR!
ecommerce-backend-app-1 | Failed at the [email protected] start script.
ecommerce-backend-app-1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
ecommerce-backend-app-1 |
ecommerce-backend-app-1 |
ecommerce-backend-app-1 | npm ERR! A complete log of this run can be found in:
ecommerce-backend-app-1 | npm ERR! /root/.npm/_logs/2023-09-10T08_03_32_813Z-debug.log
ecommerce-backend-app-1 exited with code 1
1条答案
按热度按时间oknwwptz1#
看起来nest将默认的构建路径从dist更改为build。
我不得不将start:prod脚本更改为
"node build/src/main"