Container entrypoints and exec
A container entrypoint is the initial program launched by the container runtime. Bash can validate configuration and prepare application arguments before launching the main program. Docker's JSON-array (exec) form of ENTRYPOINT avoids an implicit shell wrapper; shell-form instructions introduce a shell. A Bash entrypoint can explicitly replace itself with exec "$@" after validation. Successful exec preserves the process identity and never returns to the wrapper. A failed exec is an error; validate the requested command and use an explicit failure path.
Process identity and signals
Inside a Linux PID namespace the first process is PID 1. It has special signal semantics and responsibility for reaping orphaned children. Replacing the shell removes one layer but does not make the application a correct init process; it must handle termination and children appropriately, or use a reviewed init mechanism. When a wrapper must remain, it needs deliberate signal forwarding and child status collection. Never assume forwarding to one PID covers all descendants. The examples launch ordinary local Bash children, not containers. Use the dedicated Docker and Kubernetes tracks for runtime setup, image lifecycle and orchestration. No socket access is needed here. The local signal example checks descriptor opening and the specific child exit status 143. This is a deliberately handled termination, not a general guarantee of signal forwarding or PID 1 behavior.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code. jq and GNU coreutils are external dependencies for selected examples. Use only the explicit local mock paths; do not use real accounts, clusters or sockets.
Replace a wrapper without changing its PID
bash -c ' before=$BASHPID exec bash -c '\''[[ $BASHPID == "$1" ]] || exit 1; printf "same PID\n"'\'' child "$before" exit 1' Expected stdout:
same PIDThe new Bash process compares its actual PID with the original wrapper PID.
Preserve entrypoint arguments and status
entry() ( (( $# > 0 )) || exit 2 exec "$@")if entry bash -c 'printf "[%s]\n" "$1"; exit 7' app 'daily report'; then exit 1else rc=$? [[ $rc == 7 ]] || exit 1 printf 'status=%s\n' "$rc"fiExpected stdout:
[daily report]status=7The outer shell waits for the replaced child and receives its status; the space stays in one argument.
Forward TERM to a known local child
mkfifo ready || exit 1exec 3<>ready || exit 1bash -c 'handler() { printf "%s\n" terminated; exit 143; }trap handler TERMprintf "ready\n" >&3 || exit 1for ((i=0;i<40;i++)); do sleep 0.05; doneexit 3' &child=$!trap 'kill -TERM "$child" 2>/dev/null || :; wait "$child" 2>/dev/null || :' EXITIFS= read -r -t 2 -u 3 token || exit 1[[ $token == ready ]] || exit 1kill -TERM "$child" || exit 1if wait "$child"; then exit 1; else rc=$?; fitrap - EXIT[[ $rc == 143 ]] || exit 1exec 3>&- || exit 1rm -- ready || exit 1printf 'status=%s\n' "$rc"Expected stdout:
terminatedstatus=143Readiness ensures the handler has been installed before sending TERM. The test only targets the owned child; it is not a PID namespace or process-group test.
Common mistakes
Do not put exec before validation or expect a later cleanup line to run after successful replacement. Do not equate ordinary local PID tests with PID 1 behavior.
Practice
Change the synthetic application argument to an empty string and verify its boundary. Explain when a wrapper needs to remain and how you would test signals in an approved runtime.
Next: Readiness checks and bounded polling