是否可以从包含操作系统的.img文件创建docker映像 [英] Is it possible to create docker image from .img file containing OS
问题描述
是否可以将包含OS(Arch Linux)的 .img
文件转换为Docker映像?更准确地说,我想 dockerize 一个RuneAudio Raspberry Pi映像。
Is it possible to convert an .img
file containing an OS (Arch Linux) into a Docker image? More precisely I want to dockerize a RuneAudio Raspberry Pi image.
推荐答案
从完整的操作系统映像通常是次优过程。操作系统映像将包含在Docker环境中根本不需要的各种内容,这仅意味着结果映像将变得不必要地大。
Producing a Docker image from a full operating system image is often a sub-optimal process. The operating system image is going to include a variety of things that are simply not necessary in the Docker environment, which simply means that the resulting image is going to be unnecessarily large.
也就是说,如果您仍要尝试此操作,请使用guestfish 命令> libguestfs 软件包非常简单:
That said, if you want to try this anyway, the guestfish
command from the libguestfs package makes this very simple:
guestfish --ro -a RuneAudio_rpi_0.3-beta_20141029_2GB.img -m /dev/sda5:/ tar-out / - |
docker import - runeaudio
这将创建 runeaudio
泊坞窗映像,其中包含 RuneAudio_rpi_0.3-beta_20141029_2GB.img
磁盘映像的内容。请注意,这当然只能在Raspberry Pi上运行的Docker下运行,并且生成的图像在没有进一步修改的情况下也不一定能正常工作。
That will create a runeaudio
docker image with the contents of the RuneAudio_rpi_0.3-beta_20141029_2GB.img
disk image. Note that this will, of course, only run under Docker running on a Raspberry Pi, and the resulting image isn't necessarily going to work without further modification.
您可以也可以通过在本地安装磁盘映像来完成相同的操作:
You can also accomplish the same thing by mounting the disk image locally:
losetup -P /dev/loop0 RuneAudio_rpi_0.3-beta_20141029_2GB.img
mount /dev/loop0p5 /mnt
tar -C /mnt -cf - | docker import - runeaudio
umount /mnt
losetup -d /dev/loop0
我喜欢 guestfish
,因为它不需要root访问权限,并且不需要弄乱循环设备和挂载点,因此设置和清理工作更少。
I like guestfish
because it doesn't require root access, and doesn't require mucking about with loop devices and mountpoints, so there's less setup and cleanup.
这篇关于是否可以从包含操作系统的.img文件创建docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!