我使用运行yarn tsc
的docker构建了我的项目。当我运行docker run -p88:5011 accounts2
我收到错误PM2 error: Error: Script not found: /home/accounts/dist/server/index.js
,如果我手动遵循该过程,则会显示该错误。
这是我的docker文件
FROM node:10.16-alpine
# Install PM2
RUN npm install pm2 -g
# Add bash support to image
RUN apk add --no-cache bash
# Create service directory
RUN mkdir -p /home/accounts
WORKDIR /home/accounts
# Copy working files
COPY package.json /home/accounts
COPY . /home/accounts
# Install dependencies
RUN yarn install
RUN yarn tsc
EXPOSE 5011
# Start command
CMD [ "pm2-runtime", "process.yml" ]
我的process.yml
apps:
- script: ./dist/server/index.js
name: accounts
instances: maad
exec_mode: cluster
watch: false
autorestart: true
out_file: /dev/null
ignore_watch:
- logs
- node_modules
- worker\.js
- \.git/index\.lock
- \.log
- \.lock
watch_options:
followSymlinks: false
DIR结构
home/
.circleci/
config.yml
src/
dist/
server/
index.js
process.yml
答案 0 :(得分:0)
您正在将应用程序复制到/home/accounts
,该目录不是工作目录,应该是
WORKDIR /home/accounts-service
COPY . .
或者您将WORKDIR设置为
WORKDIR /home/accounts
就像在容器启动pm2-runtime
时查看当前工作目录一样,就像您在process.yml
中使用相对路径一样。
script (string) ”./api/app.js” script path relative to pm2 start