Dockerfile: Use JSON Notation for CMD and ENTRYPOINT

Shell form for CMD or ENTRYPOINT can mis-handle arguments and signals. Use JSON exec form for predictable container startup behavior.

Problem

Using shell notation for CMD or ENTRYPOINT may cause incorrect parsing. This leads to unexpected behavior at runtime.

Description

Shell form passes commands through a shell, which changes argument parsing and signal handling. In containers, this can break graceful shutdown behavior and produce subtle runtime bugs when arguments contain spaces, quotes, or environment substitutions.

JSON exec form expresses the command as an argument array and avoids shell interpretation. That makes startup behavior clearer and easier to reason about in orchestration environments where signal forwarding and predictable process trees matter.

Related rules: avoid multiple CMD or ENTRYPOINT instructions, avoid multiple HEALTHCHECK instructions, use absolute WORKDIR paths.

Solution

Use JSON array form for CMD and ENTRYPOINT. Keep process startup explicit so runtime behavior remains deterministic across environments.

Problematic code

FROM ubuntu:20.04
USER nobody
# Shell form may misinterpret arguments
CMD echo "Hello World"
ENTRYPOINT /usr/local/bin/start-app

Verified code

FROM ubuntu:20.04
USER nobody
# JSON notation ensures correct parsing of arguments
CMD ["echo", "Hello World"]
ENTRYPOINT ["/usr/local/bin/start-app"]

Source of the description

Dockerfile reference: CMD, ENTRYPOINT