From Docker Container to Bootable Linux Disk Image
In other words, can we create a disk image having exactly the same Linux userland a running container has and then boot from it? The following steps could be done directly on a Linux host machine, but since I use macOS at the moment, I’ll start another Debian container as a builder machine:
We need to create a sufficiently-sized image file first:
Then create a partition on the newly created disk image:
Mount this image, format it using filesystem and copy content of the tar archive to it:
Finally, we need to install the bootloader and unmount the image:
As a result of the steps from above, we will have a disk image in the working directory. For example, one can easily boot a QEMU virtual machine using the image:
Or VirtualBox machine by converting the raw image to VDI disk:
If Debian’s ~400 MB is too much for you, Alpine Linux offers comparable functionality under a total of 100 MB:
I created a project to automate the creation of disk images using Docker.
Source: micromind.me