Docker CMD exec-form for multiple command execution

后端 未结 1 744
灰色年华
灰色年华 2021-01-31 15:53

Here is a silly example of running multiple commands via the CMD instruction in shell-form. I would prefer to use the exec-form, but I don\'t know

1条回答
  •  离开以前
    2021-01-31 16:36

    The short answer is, you cannot chain together commands in the exec form.

    && is a function of the shell, which is used to chain commands together. In fact, when you use this syntax in a Dockerfile, you are actually leveraging the shell functionality.

    If you want to have multiple commands with the exec form, then you have do use the exec form to invoke the shell as follows...

    CMD ["sh","-c","mkdir -p ~/my/new/directory/ && cd ~/my/new/directory && touch new.file"]
    

    0 讨论(0)
提交回复
热议问题