是否可以在Docker容器中挂载ISO? [英] Is it possible to mount an ISO inside a docker container?

查看:1454
本文介绍了是否可以在Docker容器中挂载ISO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个docker容器(基于官方centos:6.4映像)构建一个ISO,然后我需要对其进行挂载和验证.我无法使用以下方式挂载ISO:

I am using a docker container (based on the official centos:6.4 image) to build an ISO which I then need to mount and verify. I am unable to mount the ISO using:

sudo mount -o loop /path/to/iso /mnt

赠予:

mount: Could not find any loop device. Maybe this kernel does not know
   about the loop device? (If so, recompile or `modprobe loop'.)

看起来内核已编译,没有循环设备支持.是否可以构建支持循环设备的docker映像?我找不到关于此的任何信息,但是,查看此线程似乎这可能是一个持续不断的话题.

It looks like the kernel has been compiled without loop device support. Is it possible to build docker images which support loop devices? I couldn't find any information on this, however, looking at this thread it seems that this may be an ongoing topic.

我想知道是否有办法避免这种限制?

I wonder if there is a way to circumvent this limitation?

推荐答案

要将ISO挂载到容器中,您需要做两件事:

To mount an ISO inside a container, you need two things:

  • 访问循环设备,
  • 允许挂载文件系统.

默认情况下,Docker会同时锁定这两件事.这就是为什么您收到该错误消息的原因.

By default, Docker locks down both things; that's why you get that error message.

最简单的解决方案是以特权模式启动容器:

The easiest solution is to start the container in privileged mode:

docker run --privileged ...

更细粒度的解决方案是深入研究设备的cgroup和容器功能以提供所需的权限.

A more fine-grained solution is to dive down into the devices cgroup and container capabilities to give the required permissions.

请注意,您不能将特权操作作为Dockerfile的一部分执行;即,如果您需要将该ISO挂载到Dockerfile中,则将无法执行该操作.

Note that you cannot execute privileged operations as part of a Dockerfile; i.e. if you need to mount that ISO in a Dockerfile, you won't be able to do it.

但是,我建议您查看 Xorriso ,尤其是 osirrox 工具,它使您可以像提取tar文件一样从ISO映像中提取文件,而无需需要任何特殊访问权限,例如:

However, I recommend that you have a look at Xorriso and specifically the osirrox tool , which lets you extract files from ISO images just like you would extract a tar file, without requiring any kind of special access, e.g.:

osirrox -indev /path/to/iso -extract / /full-iso-contents

这篇关于是否可以在Docker容器中挂载ISO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆