简体   繁体   中英

Run PM2 Docker with specific environment

I have been trying to pass the environment to my PM2 process so that I can target development or production .

My Dockerfile is the following:

FROM keymetrics/pm2:latest
COPY dist dist/
COPY pm2.json .
CMD ["pm2-runtime", "start", "pm2.json"]

I have the following pm2.json:

{
  "name": "my-app",
  "script": "dist/server.js",
  "instances": "1",
  "env": {
    "NODE_ENV": "development"
  },
  "env_production" : {
    "NODE_ENV": "production"
  }
}

And I couldn't manage to get the environment set properly so when I access process.env.NODE_ENV I always get "none" back.

I have tried changing the CMD to:

CMD ["pm2-runtime", "start", "pm2.json", "--env", "production"] and no joy.

I have also tried to get the environment variable set in the dockerfile like this:

ENV NODE_ENV=production and that's not picked up either.

I have also checked the latest PM2 documentation and swapped the pm2.json with a ecosystem.config.js with pretty much the same structure but that hasn't work either.

What am I missing? I'm sure that has to be something really easy to fix but can't get it to work.

THanks

CMD [ "pm2-runtime", "start", "ecosystem.config.js", "--env=production"]对我CMD [ "pm2-runtime", "start", "ecosystem.config.js", "--env=production"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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