Receiving signals in Docker

In a Dockerfile, RUN, CMD and ENTRYPOINT instructions all have two possible forms:

When you use shell form, the executable runs as a child process, which doesn't pass signals. Therefore, Docker recommends using the JSON array form.

However, the shell form is more flexible. For example, it allows variable substitution. (This can be useful, for example, when you want to reuse a Dockerfile for different projects by using an instruction like CMD python -m ${PROJECT}.)

If you want the best of both worlds (i.e. a container that receives signals, but a Dockerfile with shell form instructions), you can use exec to run the command in the shell form:

- CMD python -m ${PROJECT}
+ CMD ["sh", "-c", "exec python -m ${PROJECT}"]

Resources & further reading