【问题标题】:How to set a different Dockerfile CMD depending on environment?如何根据环境设置不同的 Dockerfile CMD?
【发布时间】:2017-02-05 12:58:43
【问题描述】:

我需要根据我所处的环境设置不同的 Dockerfile CMD。在我的特定情况下,我需要根据我是在开发环境、暂存环境还是生产环境中运行不同的 NPM 脚本。我想知道最好的方法是什么?

例如,在开发中我的 CMD 将是:CMD [“npm”、“run”、“dev”],而在生产中它会是:CMD [“npm”、“run”、“prod”]。

【问题讨论】:

    标签: dockerfile


    【解决方案1】:

    您可以将依赖于环境的命令包装在脚本中。

    cmd.sh

    if [ "$ENV" -eq "production" ]; then
      npm prod
    fi
    
    if [ "$ENV" -eq "development" ]; then
      npm dev
    fi
    

    并且,在Dockerfile;

    ...
    COPY cmd.sh /workdir/cmd.sh
    ...
    CMD [ "./cmd.sh" ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多