keymetrics / docker-pm2

🐳 Official Docker Image for PM2 runtime
https://hub.docker.com/r/keymetrics/pm2
MIT License
475 stars 60 forks source link

pm2-dev does not restart server on file changes #22

Open soosap opened 7 years ago

soosap commented 7 years ago

I have the following docker-compose.yml file:

version: '3.2'

services:
  backend:
    image: keymetrics/pm2-docker-alpine:8
    ports:
      - 3000:3000
    working_dir: /var/www
    command: ["pm2-dev", "start", "process.yml"]
    volumes:
      - "../..:/var/www"

I am further using the following process.yml pm2 configuration:

---
apps:
  - script: 'src/server.js'
    name: 'my-app'
    interpreter: 'babel-node'
    cwd: '/var/www'

The app starts alright. Unfortunately, it does not react to file changes. docker exec -it <container_id> sh 'ing into the container, I see that the file changes are propagated correctly. Yet, the server is not being restarted from within the container.

Trying the same thing outside a docker container works as expected. File changes trigger a restart with pm2-dev.

itzrahulsoni commented 6 years ago

I am facing the same issue. Any updates?

hehachris commented 6 years ago

I had the same issue. Took me 2 hours to find this...

When working with NFS devices you’ll need to set usePolling: true as stated in this chokidar issue.

Bottom of the page: http://pm2.keymetrics.io/docs/usage/watch-and-restart/

bruceragon commented 6 years ago

As stated by @hehachris adding usePolling: true in the ecosystem.config.js file worked for me.

module.exports = {
    apps: [
        {
            name: 'token',
            script: 'app.js',
            watch: true,
            "watch_options": {
                usePolling: true
            },
            env: {
                PORT: 3002
            },
            env_production: {
                NODE_ENV: 'production'
            }
        }
    ]
};