Is it possible to create docker image from .img file containing OS

后端 未结 1 1983
后悔当初
后悔当初 2021-02-06 17:03

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

1条回答
  •  太阳男子
    2021-02-06 17:51

    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.

    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 
    

    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
    

    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.

    0 讨论(0)
提交回复
热议问题