Dockerfile: create and mount a disk image at build time

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 in the last command: mount failed: Unknown error -1

.

Is there a way to achieve what I want to do?

+3


source to share


2 answers


You need features --privileged

or --cap-add

that has docker run

, but is not supported for docker build

. So, with the current version of Docker, you can't .

See this comment:



A significant number of docker users require the -cap-add or -privileged capability in the build command to mimic what is in the run command.

This is why this ticket has been open for 3 years, with people constantly calling, even if the escorts are not interested in providing users with what they want on this particular occasion.

Alternatively, you can move the commands RUN

to the script that should run when the container starts (and add the mentioned flag --privileged

or --cap-add=SYS_ADMIN

)

+3


source


They (docker) always prefer to ignore what people actually want, privileged build is just one thing, I could easily list quite a few, for example they ditched a function that has a ADD

remote target and automatically fetch it.



0


source







All Articles