How can I use a variable inside a Dockerfile CMD?

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

Inside my Dockerfile:

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

Error:

Comma         


        
4条回答
  •  一生所求
    2020-12-04 11:56

    When you use an execution list, as in...

    CMD ["django-admin", "startproject", "$PROJECTNAME"]
    

    ...then Docker will execute the given command directly, without involving a shell. Since there is no shell involved, that means:

    • No variable expansion
    • No wildcard expansion
    • No i/o redirection with >, <, |, etc
    • No multiple commands via command1; command2
    • And so forth.

    If you want your CMD to expand variables, you need to arrange for a shell. You can do that like this:

    CMD ["sh", "-c", "django-admin startproject $PROJECTNAME"]
    

    Or you can use a simple string instead of an execution list, which gets you a result largely identical to the previous example:

    CMD django-admin startproject $PROJECTNAME
    

提交回复
热议问题