Skip to content
All writing Part 05 of 12 · 在容器裡遙控 Chrome 的完整路由
Engineering · 3 min read

Docker Entrypoint:開店前的檢查清單

容器的 entrypoint 腳本先啟動 socat、確認存活,再用 exec 把 PID 1 交給 Chrome。沒有 exec,Chrome 永遠收不到 SIGTERM。

開店檢查清單

容器就像一間店。entrypoint 腳本是 Kubernetes 啟動時跑的開店檢查清單。

chrome-entrypoint.sh socat ... & 背景啟動接線員 kill -0 $SOCAT_PID 存活檢查 死了 中止(exit 1) 活著 繼續 exec chrome "$@" PID 1 交接 + 轉送所有 Helm 參數

PID 1 = 店長徽章

每個容器有一個主程序(PID 1)。Kubernetes 送 SIGTERM(「請關店」)只給 PID 1。

沒有 exec PID 1 = 腳本 K8s 送 SIGTERM 到這裡 Chrome(PID 2)聽不到 有 exec PID 1 = Chrome K8s 送 SIGTERM 到這裡 腳本已消失,Chrome 自己處理

沒有 exec,Chrome 永遠聽不到「請關店」。Kubernetes 等 30 秒,直接殺掉所有程序。

參數從哪來?

Helm deployment.yaml args: ['--headless', '--remote-debugging-port=9223'] K8s 執行 entrypoint.sh --headless --remote-debugging-port=9223 = "$@" exec chrome --headless --remote-debugging-port=9223 "$@" 原封不動轉送所有參數

Readiness probe 每 15 秒跑 wget http://127.0.0.1:9222/json/version。這個請求經過 socat。socat 死了,probe 就失敗,Kubernetes 把 Pod 從 DNS 移除。

「exec 不是執行一個程式。它是把自己變成那個程式。」


參考來源:

Related:port contract 與設定鏈(這些參數的來源),或回到系列總覽

Tags #kubernetes #chrome-devtools #containers
// connect

Be brave | Be wise | Be grateful

21 BreakinCode

// elsewhere
LinkedInMedium (lang: en)Youtube
wh:~$William Hung· © 2026 Taipei · GMT+8 · Available for collaboration