Run mock during "docker build"

I want to create a Docker image with a mock root_cache (and some package in the yum cache, but let’s keep it simple and ignore this). To do so I have a RUN mock -r <config> --init in the Dockerfile. Unfortunately unless I use “–privileged” the mock call fails with both chroot (/bin/mount -n -t proc proc /var/lib/mock/<config>/root/proc) and systemd-nspawn (/bin/mount -n --bind /var/cache/mock/<config>/yum_cache/ /var/lib/mock/<config>/root/var/cache/yum/)… and I can’t use “–privileged” with “docker build”, only with “docker run”.

I’m using Fedora 30.

Docker build

docker build --cap-add=SYS_ADMIN foo

Docker run…

docker run --privileged --cap-add=SYS_ADMIN fedora:30 /bin/bash

dnf clean all && dnf -y install mock

Enjoy :wink:

1 Like

What version of docker are you using?

$ rpm -qf $(which docker)
$ docker build --cap-add=SYS_ADMIN
unknown flag: --cap-add
See 'docker build --help'.
1 Like