[英]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
.我一直在尝试将环境传递给我的 PM2 进程,以便我可以针对development
或production
。
My Dockerfile
is the following:我的Dockerfile
如下:
FROM keymetrics/pm2:latest
COPY dist dist/
COPY pm2.json .
CMD ["pm2-runtime", "start", "pm2.json"]
I have the following pm2.json:我有以下 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.而且我无法正确设置环境,因此当我访问process.env.NODE_ENV
我总是得到“none”的回复。
I have tried changing the CMD to:我尝试将 CMD 更改为:
CMD ["pm2-runtime", "start", "pm2.json", "--env", "production"]
and no joy. CMD ["pm2-runtime", "start", "pm2.json", "--env", "production"]
没有乐趣。
I have also tried to get the environment variable set in the dockerfile like this:我还尝试在 dockerfile 中设置环境变量,如下所示:
ENV NODE_ENV=production
and that's not picked up either. ENV NODE_ENV=production
并且也没有被接受。
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.我还检查了最新的 PM2 文档,并将 pm2.json 与具有几乎相同结构的生态系统.config.js 交换,但这也不起作用。
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"]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.