Trying to run my nestjs app with mariadb using docker compose
尝试使用docker compose在MariaDB中运行我的nestjs应用程序
here is my 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"]
and dockercompose.yml
和dockercompose.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
i am getting the following error
我收到以下错误
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
更多回答
your dockerfile is working fine, I think you need to provide some more details about the project
您的dockerfile运行良好,我认为您需要提供有关该项目的更多细节
The error message includes a path /usr/src/app
(without an e
) that doesn't seem to appear in your Docker setup at all; can you double-check that the file contents you've posted are correct? The app
container has a volumes:
block that could cause this error, if the paths matched, and I'd delete that. You're not there yet but the networks:
setup will also cause problems and I'd delete the two networks:
blocks as well.
错误消息包括一个路径/usr/src/app(没有e),它似乎根本没有出现在您的Docker设置中;您能再次检查您发布的文件内容是否正确吗?如果路径匹配,应用程序容器具有可能导致此错误的Voluments:块,我会将其删除。现在还没有,但网络:安装程序也会导致问题,我也会删除两个网络:块。
@DavidMaze i added those tring to mitigate the error (following a blog posts)
@DavidMaze我添加了那些Tring以缓解错误(跟随博客帖子)
优秀答案推荐
Looks like nest changed the default build path from dist to build.
看起来Nest将默认构建路径从dist更改为Build。
I had to change the start:prod script to "node build/src/main"
我不得不将Start:Prod脚本更改为“node Build/src/main”
更多回答
我是一名优秀的程序员,十分优秀!