简体   繁体   English

Docker和PM2:基于字符串的CMD和环境变量

[英]Docker & PM2: String based CMD with environment variables

I'm currently using the shell -form of CMD in Docker for launching my node app: 我目前在Docker中使用CMDshell -form来启动我的节点应用程序:

CMD /usr/src/app/node_modules/.bin/trifid --config $TRIFID_CONFIG

The env-var TRIFID_CONFIG is set to a default in the Dockerfile : 将env-VAR TRIFID_CONFIG设置在默认Dockerfile

ENV TRIFID_CONFIG config.customer.json

This makes it easy to pass another config file for dev-environments for example. 例如,这使得为dev环境传递另一个配置文件变得容易。

Now I try to switch this to PM2 for production. 现在我尝试将其切换到PM2进行生产。 However it looks like all PM2 samples are using the "exec" form which from what I understood does not evaluate ENV-vars. 然而,看起来所有PM2样本都使用“exec”形式,根据我的理解,它不会评估ENV-vars。 I tried the shell-form with PM2: 我用PM2尝试了shell-form:

CMD pm2-docker /usr/src/app/node_modules/trifid/server.js --config $TRIFID_CONFIG

But it looks like the variable is not evaluated like this, it fails back to default on execution. 但看起来变量没有像这样评估,它在执行时失败回到默认值。

What would be the proper way to handle this with PM2 inside a Docker image? 在Docker镜像中使用PM2处理此问题的正确方法是什么?

I had a discussion on Github and meanwhile figured it out: 我对Github进行了讨论并同时弄明白了:

CMD pm2-docker /usr/src/app/node_modules/.bin/trifid -- --config $TRIFID_CONFIG

So the trick is to use -- after the command and the rest will be passed as argument. 所以诀窍是使用--在命令之后,其余的将作为参数传递。 If I use the shell form env-vars do seem to get evaluated properly. 如果我使用shell形式env-vars似乎正确评估。

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

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