Dan Prince
Dan Prince

Reputation: 30009

PM2 Won't Start Inside Docker

Trying to get a node app running and reloading from a volume inside docker, using docker-compose.

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.

The docker-compose.yml file defines a simple web service.

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

Which uses a fairly simple Dockerfile.

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

Which calls npm start:

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

Which refers to 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.

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.

Upvotes: 3

Views: 3660

Answers (1)

Unitech
Unitech

Reputation: 5991

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:

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

Upvotes: 1

Related Questions