Skip to content
All writing

Docker Entrypoint: The Morning Checklist

A container entrypoint script starts socat, verifies it is alive, then hands PID 1 to Chrome with exec. Without exec, Chrome never receives SIGTERM.

The Morning Checklist

A container is a store. The entrypoint script is the morning checklist that Kubernetes runs once at startup.

Entrypoint startup checklist chrome-entrypoint.sh starts socat in the background, aborts with exit 1 if socat is dead, and otherwise hands PID 1 to Chrome with exec and forwards all Helm args. chrome-entrypoint.sh socat ... & start receptionist kill -0 $SOCAT_PID alive check abort (exit 1) continue exec chrome "$@" PID 1 handoff + forward all Helm args DEAD ALIVE

PID 1 = The Manager Badge

Every container has one main process (PID 1). Kubernetes sends SIGTERM (“please close”) only to PID 1.

PID 1 with and without exec Without exec the script is PID 1 and gets SIGTERM, so Chrome as PID 2 never hears it; with exec Chrome is PID 1 and handles SIGTERM itself. Without exec PID 1 = script K8s sends SIGTERM here Chrome (PID 2) never hears it With exec PID 1 = Chrome K8s sends SIGTERM here script is gone, Chrome handles it

Without exec, Chrome never hears “please close.” Kubernetes waits 30 seconds, then kills everything.

Where Do the Arguments Come From?

How Helm args reach Chrome The args in Helm deployment.yaml become "$@" when Kubernetes runs entrypoint.sh, and exec chrome "$@" forwards them to Chrome unchanged. Helm deployment.yaml args: ['--headless', '--remote-debugging-port=9223'] K8s runs entrypoint.sh --headless --remote-debugging-port=9223 = "$@" exec chrome --headless --remote-debugging-port=9223 "$@" forwards all args as-is

The readiness probe runs wget http://127.0.0.1:9222/json/version every 15 seconds. This request goes through socat. If socat dies, the probe fails and Kubernetes removes the pod from DNS.

“exec does not run a program. It becomes that program.”


References:

Related: see the port contract and config chain that feeds these args, or go back to the series overview.

↑↓ navigate ↵ open esc close