Docker Bind Mount Permission Denied: UID/GID、Non-root 與 Rootless 的取捨
English Abstract: A classic Docker bind mount failure: the container writes to a host directory and gets Permission denied, even though the host user clearly owns that directory. The root cause is almost always a UID/GID mismatch between the host filesystem and the container process — Linux permission checks only look at numeric IDs, not usernames. This post compares three fixes: pinning the container to a specific UID with --user , the PUID/PGID entrypoint pattern popularized by LinuxServer.io images, and Rootless Docker / Podman's user namespace remapping ( userns-remap ), along with the security and portability trade-offs of each. 用 -v 把 host 目錄掛進 container,裡面的程式想寫入卻得到 Permission denied,即使在 host 上明明對這個目錄有讀寫權限,這是最常見的 bind mount 問題之一。問題幾乎都出在 host 檔案的 owner UID/GID,跟 container 內 process 實際跑的 UID/GID 對不上——Linux 的權限檢查只認數字,不認「使用者名稱」。這篇文章說明三種常見解法:用 --user 直接指定 UID、用 PUID/PGID entrypoint 動態對齊、以及 Rootless Docker/Podman 的 user namespace 重映射,並比較三者在安全性、可攜性與設定複雜度上的取捨。 (一...