gpt4 book ai didi

Dockerfile:在构建期间创建和挂载磁盘镜像

转载 作者:行者123 更新时间:2023-12-01 00:25:38 26 4
gpt4 key购买 nike

我正在尝试在 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 ,我在最后一个命令中收到以下错误消息: mount failed: Unknown error -1 .

有什么办法可以实现我想做的事吗?

最佳答案

您需要 --privileged--cap-add docker run 的功能确实有,但 docker build 不支持.因此,从当前的 Docker 版本开始,you can't .
this评论:

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.


作为替代方案,您可以移动 RUN命令应该在容器启动时运行的脚本(并添加提到的 --privileged 标志,或 --cap-add=SYS_ADMIN )

关于Dockerfile:在构建期间创建和挂载磁盘镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45169593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com