我正在尝试在Dockerfile构建过程中构建和挂载自定义磁盘映像:
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
运行docker build时,我在最后一个命令中收到以下错误消息:挂载失败:未知错误-1.
有什么办法可以实现我想要的?
最佳答案
您将需要docker run确实具有的–privileged或–cap-add功能,但是docker build不支持该功能.因此,从当前的Docker版本you can’t开始.
原文链接:https://www.f2er.com/docker/532741.htmlA 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.
或者,您可以将RUN命令移动到在容器启动时应运行的脚本(并添加提到的–privileged标志或–cap-add = SYS_ADMIN)