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

socat:在 Pod 裡放一個接線員

Chrome 128 只聽 localhost。socat 在同一個 Pod 裡把外部請求轉接到 Chrome 的本地 port,繞過這個限制。

問題

Chrome 只聽群組聊天(127.0.0.1)。API Pod 在另一支電話上,只能打分機。Chrome 不接外線。

修復

socat 是 Chrome Pod 裡的接線員。它坐在前台(0.0.0.0:9222)接所有外線。有電話來,socat 走到 Chrome 的群組聊天(127.0.0.1:9223)轉達,再把回覆帶回去。

API Pod 打分機 10.0.2.3:9222 Chrome Pod socat 接線員 0.0.0.0:9222 Chrome 127.0.0.1:9223 轉接(同 Pod = 同 localhost) 回覆

Chrome 以為 socat 是本地的 App。因為 socat 就在同一個 Pod 裡。

指令:

socat TCP-LISTEN:9222,fork,reuseaddr,bind=0.0.0.0 TCP:127.0.0.1:9223 &
  • fork:同時接多通電話
  • reuseaddr:重啟後重用 port
  • bind=0.0.0.0:接所有外線
  • &:背景執行

如果 Docker image 把 relay port 寫死(例如 CHROME_FORWARD_PORT=9222),部署時必須覆蓋這個值。不覆蓋的話,socat 轉到錯誤的 port。Pod 啟動,沒有報錯,但連線全失敗。見 entrypoint 如何啟動 socat

「Chrome 以為接線員是隔壁同事在傳話。它不知道那通電話其實來自另一支電話。」


參考來源:

Related:Chrome 128 的 localhost 鎖定(造成這個問題的原因),或回到系列總覽

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