Search code examples
dockerraspberry-pi3raspbianvolumio

How to convert .img to a Docker image


I am novice at Docker. By this post I made a .img file for Docker, but how import it as Docker image I don't know...


Solution

  • 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.

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