【问题标题】:Why am I not able to delete a directory when building a container with podman?为什么使用 podman 构建容器时无法删除目录?
【发布时间】:2021-05-15 13:42:25
【问题描述】:

我正在 GitLab 的 CI/CD 管道内的 Dockerfile 中使用无根 podman 构建自定义映像。

在这个容器中,我想删除一个目录以缩小生成图像的大小。

例如这样:

FROM ubuntu:20.04

# Disable apt cache
COPY ./02nocache /etc/apt/apt.conf.d/02nocache
RUN rm -rf /var/cache/apt/archives

当我运行它时,它会显示以下内容:

STEP 6: RUN rm -rf /var/cache/apt/archives
rm: cannot remove '/var/cache/apt/archives/lock': File exists
rm: cannot remove '/var/cache/apt/archives/partial': File exists
error building at step {Env:[PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DEBIAN_FRONTEND=noninteractive] Command:run Args:[rm -rf /var/cache/apt/archives] Flags:[] Attrs:map[] Message:RUN rm -rf /var/cache/apt/archives Original:RUN rm -rf /var/cache/apt/archives}: error while running runtime: exit status 1

我这样调用构建:

build-image:
    stage: prepare
    image: buildah/buildah
    script:
        ...
        - podman build -t $CONTAINER_TEST_IMAGE .
        ...

到目前为止,我尝试使用 sudo 调用 podman,我尝试使用 sudo 运行 rm 但无济于事。在网上搜索这个问题时,我没有找到任何帮助我的东西。

有人知道如何解决这个问题吗?

【问题讨论】:

  • 我无法重现您在此处显示的示例的问题(在 Fedora 33 上使用 Podman 2.2.1)。这个确切的 Dockerfile 真的会触发你的问题吗?您能否详细介绍一下您的操作系统环境?
  • 这可能与在 GitLab CI 中使用 buildah/buildah 图像运行有关。我没有在本地计算机上试用它,因为它需要在管道中运行。
  • 我看到 gitlab 有一个 cache 能力可能会导致这种行为,但看起来需要显式启用。
  • 您链接的缓存用于在作业的多次运行之间缓存文件。它不会影响使用 podman 的构建步骤。此作业也未启用缓存。

标签: ubuntu gitlab gitlab-ci podman buildah


【解决方案1】:

我想有些东西锁定了这些文件或挂载了这些文件,内核将不允许您删除这些文件或包含的目录。

【讨论】:

    猜你喜欢
    • 2022-10-16
    • 2022-07-08
    • 2021-10-01
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    • 2023-02-01
    • 2020-04-30
    • 1970-01-01
    相关资源
    最近更新 更多