How can I use a variable inside a Dockerfile CMD?

后端 未结 4 545
借酒劲吻你
借酒劲吻你 2020-12-04 11:15

Inside my Dockerfile:

ENV PROJECTNAME mytestwebsite
CMD [\"django-admin\", \"startproject\", \"$PROJECTNAME\"]

Error:

Comma         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-04 11:43

    If you want to use the value at runtime, set the ENV value in the Dockerfile. If you want to use it at build-time, then you should use ARG.

    Example :

    ARG value
    ENV envValue=$value
    CMD ["sh", "-c", "java -jar ${envValue}.jar"]
    

    Pass the value in the build command:

    docker build -t tagName --build-arg value="jarName"
    

提交回复
热议问题