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?
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.