Exec form vs. Shell form?

QuestionsQuestions8 SkillsProCustom Docker ImagesAug, 29 2025
01.0k

The ENTRYPOINT instruction in a Dockerfile can be specified in two forms: Exec form and Shell form. Here’s a comparison of the two:

Exec Form

  • Syntax:
    ENTRYPOINT ["executable", "param1", "param2"]
  • Behavior:
    • The command is executed directly without a shell.
    • It does not invoke a shell, which means that shell features (like pipes, redirection, etc.) are not available.
    • It allows for better signal handling, as the executable receives signals directly.
  • Use Case:
    • Recommended for most cases, especially when you want to ensure that the command runs as intended without shell interpretation.

Shell Form

  • Syntax:
    ENTRYPOINT command param1 param2
  • Behavior:
    • The command is run in a shell (/bin/sh -c).
    • This allows the use of shell features like pipes, redirection, and environment variable expansion.
    • However, it can lead to issues with signal handling, as the shell process receives the signals instead of the executable.
  • Use Case:
    • Useful when you need shell features or when you want to run multiple commands in a single line.

Summary

  • Exec Form: Direct execution, better signal handling, no shell features.
  • Shell Form: Runs in a shell, allows shell features, but may have signal handling issues.

In general, the Exec form is preferred for defining ENTRYPOINT in Dockerfiles.

0 Comments

no data
Be the first to share your comment!