在Docker中运行yarn tsc后找不到脚本错误

时间:2019-11-25 14:37:44

标签: typescript docker yarn

我使用运行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

1 个答案:

答案 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

pm2-application-declaration