Docker Community Forums

Share and learn in the Docker community.

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):

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!


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 ?


Step 1 – Install snapd

To install the snapd package type the following dnf command:
sudo dnf install snapd

![](data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9JzQ5MScgd2lkdGg9JzU5OCcgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJyB2ZXJzaW9uPScxLjEnLz4=)How to install snapd on Fedora Linux

How to install snapd on Fedora Linux

You must setup a symlink using the ln command, enter:
sudo ln -s /var/lib/snapd/snap /snapsnap version
Sample outputs:

snap snapd series 16 fedora 32 kernel 5.7.11-200.fc32.x86_64

Step 2 – Install and setup LXD on Fedora Linux server

Type the following snap command:
## first restart snapd using the systemctl command ##sudo systemctl restart snapd.servicesudo snap install lxd
!(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9JzIxOCcgd2lkdGg9JzU5OScgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJyB2ZXJzaW9uPScxLjEnLz4=)Install and setup LXD on Fedora Linux using snap command

Verify LXD installation

Make sure lxd service enabled on the Fedora Linux:
$ sudo snap enable lxd$ sudo snap services lxd

Service Startup Current lxd.daemon enabled active

If not active, startit:
sudo snap start lxd

Add a Linux user named ‘vivek’ to lxd group

Type the following usermod command (feel free to replace the username ‘ vivek ‘ with your actual username on Fedora Linux):
sudo usermod -a -G lxd vivekid viveknewgrp lxd
![](data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9JzIyMScgd2lkdGg9JzU5OScgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJyB2ZXJzaW9uPScxLjEnLz4=)Add a user to secondary group called lxd on Linux
At this stage log out and log in again if session not activated

Step 3 – Configure the LXD networking and storage for VM

Type the following command:
lxd init
!(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9JzIzNScgd2lkdGg9JzU5OScgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJyB2ZXJzaW9uPScxLjEnLz4=)Fedora Linux lxd init command
I suggest you use new backends such as ZFS, BTRFS, or LVM and along with DHCP based IP networking for ease of setup for each VM. As a result, you can use snapshots and other advanced features supported by new backends. You may get warning as follows:

WARNING: cgroup v2 is not fully supported yet, proceeding with partial confinement

Currenlty support for cgroups v2 is in development, but has not been rolled out. Hence, you need to ignore this warning on Fedora Linux 32.

lxd verification

Make sure the lxc client is talking to the LXD daemon:
lxc list
!(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9JzIzNicgd2lkdGg9JzU5OScgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJyB2ZXJzaW9uPScxLjEnLz4=)Fedora Linux LXD lxc list command outputs

List all available Linux LXD (Linux Containers) VM images

lxc image list images:

![](data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9JzIwOCcgd2lkdGg9JzMwMCcgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJyB2ZXJzaW9uPScxLjEnLz4=)lxc list all LXD VM images command on Fedora Linux

(click to enlarge)

Most of the images are known by several aliases. To see a list, enter:
lxc image alias list images:lxc image alias list images: | grep -i archlxc image alias list images: | grep -i debianlxc image alias list images: | grep -i fedora

Step 4. Create your first LXD VM on Fedora

It is time to create and use your first container. To create and start containers from images use the launch command:
lxc launch images:{distro}/{version}/{arch} {container-name-here}
Let us see some examples to create and start containers from various Linux distro images as per your needs.

CentOS Linux 7 and 8 container

lxc launch images:centos/7/amd64 cenots-7-vmlxc launch images:centos/8/amd64 cenots-8-vm

Fedora Linux 33 container

lxc launch images:fedora/33/amd64 fedora-33

OpenSUSE Linux 15.2 continer

lxc launch images:opensuse/15.2/amd64 opensuse-15-2

Gentoo Linux container

lxc launch images:gentoo/amd64 gentoo-linux-vm

Arch Linux

lxc launch images:archlinux/amd64 arch-linux-vm

Ubuntu Linux LTS 18.04

lxc launch images:ubuntu/18.10/amd64 ubuntu-nginx-vm

Debian Linux 9.x

lxc launch images:debian/9/amd64 debian-nfs-server-vm

Debian Linux 10.x

lxc launch images:debian/10/amd64 debian-10-vmlxc list