in part of docker document,
CMD ["executable","param1","param2"] (exec form, this is the preferred form)
CMD command param1 param2 (shell form)
what is executable, command meaning?
I have confused about that.
What I think is ll, cd, ls, chmod, cp
.
They are all executable and command.
Because I try this in dockerfile
CMD ["ll", "-a"]
It's doesn't work.
But when we type ll in teminal, it's work, I think it's just execute ll
.
I think I had some wrong concept about that.
CodePudding user response:
CMD
Usage:
- CMD
["<executable>","<param1>","<param2>"]
(exec form, this is the preferred form)
From the docs
Unlike the shell form, the exec form does not invoke a command shell. This means that normal shell processing does not happen. For example, CMD [ "echo", "$HOME" ] will not do variable substitution on $HOME. If you want shell processing then either use the shell form or execute a shell directly, for example: CMD [ "sh", "-c", "echo $HOME" ]. When using the exec form and executing a shell directly, as in the case for the shell form, it is the shell that is doing the environment variable expansion, not docker.
If you want to run your
<command>
without a shell then you must express the command as a JSON array and give the full path to the executable. This array form is the preferred format of CMD. Any additional parameters must be individually expressed as strings in the array:
CMD
["<param1>","<param2>"]
(as default parameters to ENTRYPOINT)CMD
<command> <param1> <param2>
(shell form)
If you use the shell form of the CMD, then this will execute in
/bin/sh -c
:
Coming to your problem
Exec Way
if you want to execute ll
command using executable way
then you would have two options available
- Add "sh" as first param like
CMD ["sh", "-c", "ll", "-a"]
. - Or provide absolute path of
ll
(It is alias tols -lh
) executable likeCMD [ "/bin/ls", "-lh" "-a"]
Shell way
if you want to execute ll
command using shell way
then you can use like this CMD ll