简体   繁体   English

PM2 不会在 Docker 内部启动

[英]PM2 Won't Start Inside Docker

Trying to get a node app running and reloading from a volume inside docker, using docker-compose.尝试使用 docker-compose 运行节点应用程序并从 docker 内部的卷重新加载。

The goal is to have the app running inside the container, without losing the ability to edit/reload the code outside the container.目标是让应用程序在容器内运行,而不会失去在容器外编辑/重新加载代码的能力。

I've been through PM2's docker integration advice and using keymetrics/pm2-docker-alpine:latest as a base image.我已经阅读了PM2 的keymetrics/pm2-docker-alpine:latest集成建议并使用keymetrics/pm2-docker-alpine:latest作为基础镜像。

The docker-compose.yml file defines a simple web service. docker-compose.yml文件定义了一个简单的 Web 服务。

version: '2'
services:
  web:
    build: .
    ports:
      - "${HOST_PORT}:${APP_PORT}"
    volumes:
      - .:/code

Which uses a fairly simple Dockerfile.它使用了一个相当简单的 Dockerfile。

FROM keymetrics/pm2-docker-alpine:latest
ADD . /code
WORKDIR /code
RUN npm install
CMD ["npm", "start"]

Which calls npm start :其中调用npm start

{
  "start": "pm2-docker process.yml --watch"
}

Which refers to process.yml :其中指的是process.yml

apps:
  - script: './index.js'
    name: 'server'

Running npm start locally works fine—PM2 gets the node process running and watching for changes to the code.在本地运行npm start工作正常——PM2 使节点进程运行并监视代码更改。

However, as soon as I try and run it inside a container instead, I get the following error on startup:但是,一旦我尝试在容器中运行它,我就会在启动时收到以下错误:

Attaching to app_web_1
web_1  |
web_1  |
web_1  | [PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
web_1  | [PM2] PM2 Successfully daemonized
web_1  |
web_1  |   error: missing required argument `file|json|stdin|app_name|pm_id'
web_1  |
app_web_1 exited with code 1

Can't find any good examples for a hello world with the pm2-docker binary, and I've got no idea why pm2-docker would refuse to work, especially as it's running above the official pm2-docker-alpine image.找不到任何关于 pm2-docker 二进制文件的 hello world 的好例子,我不知道为什么pm2-docker会拒绝工作,尤其是当它运行在官方pm2-docker-alpine图像之上时。

To activate the --watch option, instead of passing the --watch option to pm2-docker, just set the watch option to true in the yml configuration file:要激活 --watch 选项,而不是将 --watch 选项传递给 pm2-docker,只需在 yml 配置文件中将 watch 选项设置为 true:

apps:
  - script: './index.js'
    name: 'server'
    watch : true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM