--- title: 【軟體】Container 文件權限問題 tags: TTennis Pickup Robot disqus: hackmd --- <h1 style="text-align: center; color: orange;"> 🛠️ 【軟體】必學的 Docker 🛠️ </h1> <h2 style="text-align: center; color: skyblue;">Container 文件權限問題</h2> <center> 下圖中,`device-coding/` 是被 mount 進 container 的。\ 其中 `.cache` 是當容器運作時產生的快取檔案。 如果我直接在 host machine 中刪除,就會跳出如右錯誤  當然,看到 permission denied 就知道加 `sudo` 即可解決。 但這裡會多補充一些事情。 </center> --- </br> <h3><font color="magenza"> 1. 原因 </font> </h3> 通常這是發生在容器是以 root 身分運行,而 host machine 是以 user 身分登入。 所以 user 沒有權限刪除由 root 生出的檔案。 可用 `ls -la` 確認這點:  :::spoiler 終端訊息解釋 * 左大欄 dwxr * 第一欄:`d` 為目錄、`-` 為普通文檔 * 右邊九個要分成 3|3|3 看,分別代表 owner | group user | other users。 * `w` 為寫權限、`r` 為讀權限、`x` 為可執行權限。 * 數字欄位 * 對於目錄文件:含有的子目錄數。 * 對於普通文檔:鏈接數量。 * 兩欄名稱欄位 * 第一欄:user name * 第二欄:group name * 容量欄位 * 右大欄日期欄位 ::: </br> <h3><font color="magenza"> 2. 解決方法 </font> </h3> * **Method 1**:在容器內直接刪除。 * **Method 2**:在主機上以 root 身分刪除,`sudo rm -rf`。 * **Method 3**:更改文件擁有者:`sudo chown`。  * **Method 4**:更改 volume 路徑。 不要 mount 整個 `device-decoding/` 進 container 內,而是將 `device-decoding/` 內的各子文件或目錄一一掛載進容器內。 * **Method 5**:volumes 參數。 ```yml= volumes: - /device-docding:/device-docding:rw ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up