Profile picture
Sidharth R
  • Home
  • Posts
  • Journal
  • Home
  • Posts
  • Journal
  • Search

Shell Form vs Exec Form

Updated: 01 May 2026 ⚬ Page views: loading...

Shell form is just a string.

Exec form - JSON array syntax.

TermWhat it really means
Shell formString → runs via a shell (/bin/sh -c)
Exec formJSON array → runs directly (no shell)

Shell form:

CMD node app.js

Is equivalent to:

/bin/sh -c "node app.js"

The bourn shell is default for Linux containers. Windows containers have cmd.exe as default.

People also use powershell rather than the default.

General guidelines

RUN, use shell

RUN apt-get install jq

Rule of thumb (this is what industry follows)

Use exec form for:

  • CMD
  • ENTRYPOINT
  • production containers

Use shell form for:

  • RUN (because chaining is convenient)

Other notes

  • Exec form ensures that the long running process you specify executes as PID 1, /bin/sh -c (PID 1). Imp for ENTRYPOINT & CMD

Takeaways

  • The RUN, ENTRYPOINT & CMD instructions can be specified in shell form or exec form.
  • Shell form will inject /bin/sh -c at the beginning of the command.
  • Override the Docker default shell using
    SHELL ["/bin/bash", "-c"]
  • Shell form is required if you need variable substitution, chaining commands, piping output, I/O redirection.
  • Exec form (JSON syntax) runs the command without a shell.
  • Exec form ensures ENTRYPOINT/CMD binary is PID 1 and receives signals.
  • Exec form passes ENVs from Dockerfile to processes started with RUN, ENTRYPOINT & CMD.

ENTRYPOINT is an overwrite statement. Only the last one in the DOckerfile is used.

Use CMD for long running process.

Nerdsid.com

Links
  • Home
  • Contact
  • About
  • Posts
  • Journal
  • Quotes
  • Links worth your time
  • Notes
  • Style guide
© 2026 Sidharth R.
All content on this website is licensed under CC BY-NC-SA 4.0.