![](/img/trans.png)
[英]Incorrect permissions for file with docker compose volume? 13: Permission denied
[英]Why are Docker filesystem permissions behaving differently on GitHub Actions (Permission denied on server)
我有一個帶有 Dockerfile 的應用程序:
# From here on we use the least-privileged `node` user to run the backend.
USER node
WORKDIR /app
# This switches many Node.js dependencies to production mode.
ENV NODE_ENV production
# Copy repo skeleton first, to avoid unnecessary docker cache invalidation.
# The skeleton contains the package.json of each package in the monorepo,
# and along with yarn.lock and the root package.json, that's enough to run yarn install.
COPY --chown=node:node yarn.lock package.json packages/backend/dist/skeleton.tar.gz ./
RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz
這是由官方 Backstage CLI ( https://github.com/backstage/backstage/issues/15421 ) 生成的 dockerfile 的一部分。
當我在我的 Mac 和我同事的 Windows 機器上運行 docker 構建時,構建工作正常。
然而,當我們在 GitHub Actions 或 Microsoft ADO 上嘗試相同的構建時,docker 構建失敗並出現文件系統權限錯誤:
Step 7/11 : RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz
---> Running in b20314a0495a
tar: packages: Cannot mkdir: Permission denied
tar: packages/app/package.json: Cannot open: No such file or directory
tar: packages: Cannot mkdir: Permission denied
tar: packages/backend/package.json: Cannot open: No such file or directory
tar: Exiting with failure status due to previous errors
我做了一些谷歌搜索,發現在 tar 操作之前創建和更改上面的“節點”用戶擁有的目錄可以解決問題。
所以實際上這個 Dockerfile 在我的機器和 GitHub Actions 上都有效。 請注意前兩行 - 這是 Dockerfile 之間的全部區別:
RUN mkdir -p /app
RUN chown node /app
# From here on we use the least-privileged `node` user to run the backend.
USER node
WORKDIR /app
# This switches many Node.js dependencies to production mode.
ENV NODE_ENV production
# Copy repo skeleton first, to avoid unnecessary docker cache invalidation.
# The skeleton contains the package.json of each package in the monorepo,
# and along with yarn.lock and the root package.json, that's enough to run yarn install.
COPY --chown=node:node yarn.lock package.json packages/backend/dist/skeleton.tar.gz ./
RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz
我不明白的是:為什么第一個 Dockerfile 構建在 Mac/Windows 上成功,而在 GitHub 操作(Linux?)上失敗。 為什么 GitHub Actions 版本需要在文件夾級別進行額外的所有者更改,而 Mac/Windows 版本不需要? 也許這與Docker版本有關?
我非常確定這個問題具體發生在 Linux 上,因為它在 Windows 和 macOS 上運行在虛擬機中。 它會出現在“真正的 Linux”機器而不是虛擬機中的原因是因為用戶 ID 和組 ID 在“docker 主機”和 884065722228588 容器之間共享(更多信息參見此處)
GitHub 操作可能已為包含在 tar.gz 中的 uid/gids 以及 tar.gz 本身指定了權限,而在您本地的 macOS/Windows 上,docker 的專用 VM 沒有任何“真實”用戶管理使用 Linux。
當我使用 Bitbucket 的 CI 時,我遇到了類似的問題,它有一些關於 uids/gids 的奇怪政策。 這可能是一個類似的案例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.