Search notes:

Dockerfile: Shell vs exec form

CMD

One of the differences between using the shell form and using the exec form in a Dockerfile's CMD instruction is the expansion or non-expansion of environment variables.

Shell form

A Dockerfile with a CMD instruction using the shell form:
FROM busybox

ENV txt="Hello world"
ENV num=42

CMD echo -e "txt=$txt\nnum=$num"
docker build -q -t cmd-shell-form .
docker run --rm    cmd-shell-form 
docker rmi         cmd-shell-form
With the shell form, the docker run command prints
txt=Hello world
num=42

Exec form

A Dockerfile with a CMD instruction using the exec form:
FROM busybox

ENV txt="Hello world"
ENV num=42

CMD ["echo", "-e", "txt=$txt\nnum=$num"]
docker build -q -t cmd-exec-form .
docker run --rm    cmd-exec-form 
docker rmi         cmd-exec-form
With the exec form, the docker run command prints
txt=$txt
num=$num

Index