我在我的服务器端项目中使用了 adonis js,我按照 adonis js 官方文档之一使用 pm2 模块进行部署,我成功地在我的 docker 之外运行,但我只在我的项目中遇到错误。我在我的项目中检查了我的 docker 镜像,一切都正确。
错误
Error: Cannot find module '/var/www/server/build/app/Controllers/Http/UploadController'
Require stack:
我的图像中有文件
# We'll use the Node slim image as a base cos it's light and nice
FROM node:lts
WORKDIR /var/www/server
# Copy package.json & package-lock.json to the root of the api dir
COPY package*.json ./
# Create an .env file by copying the .env.example file
# COPY .env .env
COPY . .
# Add node_modules to the envionmental path variable so we can run binaries easily
ENV PATH /var/www/server/node_modules/.bin:$PATH
USER root
# Install the good ol' NPM modules and get Adonis CLI in the game
RUN npm install --no-optional
# We'll use PM2 as a process manager for our Node server
RUN npm i -g pm2
# Copy everything to the root of the API service docker volume, and expose port to the outside world
COPY --chown=node:node . .
# Let all incoming connections use the port below
EXPOSE 3333
# CMD npm run pm2:start
# CMD npm run pm2:start
CMD [ "pm2-runtime", "start", "pm2.config.js" ] .
运行 docker image 时出错
C:\WinNMP\WWW\ac\server>docker run 2d6d4c30b76c
2021-08-12T16:43:44: PM2 log: Launching in no daemon mode
2021-08-12T16:43:45: PM2 log: [Watch] Start watching server
2021-08-12T16:43:45: PM2 log: App [server:0] starting in -cluster mode-
2021-08-12T16:43:45: PM2 log: App [server:0] online
Error: Cannot find module '/var/www/server/build/app/Controllers/Http/UploadController'
Require stack:
- /var/www/server/build/node_modules/@adonisjs/fold/build/src/Ioc/ImportAliases.js
- /var/www/server/build/node_modules/@adonisjs/fold/build/src/Ioc/index.js
- /var/www/server/build/node_modules/@adonisjs/fold/build/index.js
- /var/www/server/build/node_modules/@adonisjs/application/build/index.js
- /var/www/server/build/node_modules/@adonisjs/core/build/standalone.js
- /var/www/server/build/server.js
at /var/www/server/start/routes.ts(anonymous):34 <---------------------getting error
29
30
31 import Route from '@ioc:Adonis/Core/Route'
32 import LoginController from 'App/Controllers/Http/LoginController'
33 import DnsController from 'App/Controllers/Http/DnsController'
34 import UploadController from 'App/Controllers/Http/UploadController'<-------getting error
35 import ProductsController from 'App/Controllers/Http/ProductsController'
36 import SiteController from 'App/Controllers/Http/SitesController'
37 import { Request } from '@adonisjs/core/build/standalone';
38
39 Route.group(() => {
1 Module.require
/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:61
2 ImportAliases.resolve
/var/www/server/build/node_modules/@adonisjs/fold/build/src/Ioc/ImportAliases.js:95
3 Ioc.require
/var/www/server/build/node_modules/@adonisjs/fold/build/src/Ioc/index.js:294
4 Ioc.use
/var/www/server/build/node_modules/@adonisjs/fold/build/src/Ioc/index.js:310