How to convert a bootable Fedora-33 LXC O/S container into a bootable Docker image container

Hello Friends:

I have a Fedora-33 LXC O/S container that I would like to convert to a bootable Docker Image. The reason I’m building this as a LXC O/S container first, is because there are many moving parts and interactions, and building it in a running LXC O/S is far easier than incrementally (iteratively) building it via a Docker(5) file (painful).

In the end, how do I take the resulting LXC O/S and create an equivalent Docker Image for it that is bootable? Keep in mind that Fedora-33 has a systemd that is part if it. (Just in case it matters).

Has anyone successfully done this, with Fedora or another distributions? And how?

I saw examples at this URL, but am unsure it works with an entire Fedora-33 filesystem O/S (maybe it does, but it doesn’t specify):

https://docs.docker.com/engine/reference/commandline/import

Thank you in advance! :blush:

You could tar the whole filesystem of your OS. Then create a Dockerfile with “FROM scratch” (=empty base image) and ADD the os.tar to it. This should extract the tar into a scratch image.

Though, there might be a partybreaker: containers do not boot! They have no own kernel, don’t boot, don’t start system service - they just start a process for the command you declared as ENTRYPOINT/CMD in your Dockerfile.

Better (but still terrible) alternative: why don’t you create your image with docker run -ti ${any base image}, perform your installation steps in the interactive terminal, stop the container and convert it to an image with docker commit ${containerid}?

Anyway you are going to create something that is painfull to maintain.

If you ask which approach is the recommended one: neither one of those above… Write a Dockerfile, do everyting inside the Dockerfile… This will give you solid base for maintainance. Automation never is easy, because you have to know exactly what you’re doing and how to put it into scripts… Magic always commes with a price :wink:

Good luck!

1 Like

Thank you. Yes, my next option was the commit option. I’ve created many very complex images from scratch via Dockerfile (i.e. pure Infrastructure as Code that I can check into GitHub/GitLab), but this one is a real pain. I may still do that, but for now a commit-based or tar-based “image” will do for MVP / Prototyping. But I concur with your general point of view. :slight_smile: Thanks for the reply!

Hello,

I think i will be going down the same track of trying to take an installed product on a VM and creating a Docker Image out of that VM.
I spent the day building a Dockerfile and got close to completing the installation of the application but got a stick in the spokes when the application tried to create its /etc/init/d/starup files. .

chmod: cannot access '/etc/init.d/appstartd ': No such file or directory

I guess the /etc/init.d belongs to the Host OS unlike the /etc/passwd file where the App installation created the local users for the mysql and jboss.

Another little fly in the ointment is that the JBoss app has One parameter that needs to be given / set during the install - that ill have to find a way to change once the container created and Up ???
Are there any examples of Virtual to Container conversions ?

Thanks,
Don