0

I am building a custom image with rootless podman from a Dockerfile within a CI/CD pipeline in GitLab.

In this container, I would like to remove a directory to slim down the size of the resulting image.

For example like this:

FROM ubuntu:20.04

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

When I run this it says the following:

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

I call the build like this:

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

So far I tried to use sudo to call podman, I tried running the rm with sudo but to no avail. When searching for this issue on the web I did not find anything that helped me out.

Does anyone know how to fix this issue?

danielnelz
  • 3,794
  • 4
  • 25
  • 35
L. Resch
  • 41
  • 1
  • 3
  • I can't reproduce the problem with the example you've shown here (using Podman 2.2.1 on Fedora 33). Does this exact Dockerfile actually trigger the problem on your end? Can you give us some details about your OS environment? – larsks Feb 12 '21 at 12:14
  • It might be related to being run in GitLab CI with the `buildah/buildah` image. I did not try it out on my local computer since it needs to run in the pipeline. – L. Resch Feb 13 '21 at 13:22
  • I see that gitlab has a [cache](https://docs.gitlab.com/ee/ci/yaml/README.html#cache) capability that could lead to this behavior, but it looks like that needs to be explicitly enabled. – larsks Feb 13 '21 at 14:23
  • The cache you linked is for caching files between multiple runs of a job. It would not affect the build step with podman. Caching is also not enabled on this job. – L. Resch Feb 15 '21 at 08:53

1 Answers1

-1

I would figure something has a lock on these files or a mount on these files and the kernel will not allow you to remove the files or the containing directory.

rhatdan
  • 392
  • 1
  • 1