I am trying to build and mount a custom disk image during the Dockerfile build process:
FROM ubuntu:16.04
RUN dd if=/dev/zero of=foo.img count=500 bs=1M
RUN mkfs.ext4 foo.img
RUN mkdir -p /media/ext4disk
RUN mount -t ext4 foo.img /media/ext4disk
Running docker build
, I get the following error message on the last command: mount failed: Unknown error -1
.
Is there any way to achieve what I want to do?
You would need the --privileged
or --cap-add
functionality that docker run
does have, but that is not supported for docker build
. So, as of current Docker version, you can't.
See this comment:
A significant number of docker users want the ability to --cap-add or --privileged in the build command, to mimic what is there in the run command.
That's why this ticket has been open for 3 years with people constantly chiming in even though the maintainers aren't interested in giving the users what they want in this specific instance.
As an alternative you can move that RUN
commands to a script that should run when container starts (and adding the mentioned --privileged
flag, or --cap-add=SYS_ADMIN
)