How to create a new CT / LXC container template ?

shodan

Active Member
Sep 1, 2022
172
55
33
Hi,

I wish to create an easily deployable, fully offline template service in proxmox.

I reviewed docker but I keep finding people having issues with using docker in CT containers.

And running docker in a VM feels wasteful.

Also I don't like the cloud-centric feel of docker in general, I want a single file, which contains my thing.

Let's say for the sake of example, that my thing is going to be a ready to go Zoneminder server, a common open source surveillance camera software.

So, I think what I would like is start with a debian 12.7 CT container, then install Zoneminder properly on it, leaving only the actual hardware configuration to be done.

Then run something like sysprep on windows, to wipe all encryption keys and unique trackers, I don't know how to do that on linux ? cloudinit ? Is that it ?

Then somehow package that as a CT template file like proxmox has

and finally, post that to some CT container repository ? Does such a thing even exist ? Should I check if someone in the world already made a Zoneminde CT container perhaps ?

Although, I suspect no such thing as a CT container repository exist,

I have asked this on the linuxcontainers forum and got the following answer.

You are not supposed to put applications in CT containers, they are system containers, so no Zoneminder or mailserver containers make sense and it doesn't make sense to have a repository

https://discuss.linuxcontainers.org/t/where-can-i-find-the-biggest-lxc-container-repository/14946

exact quote

"
LXC and LXD are meant to be used with system-containers, not application containers.
system-containers are to be treated like VMs, they just work differently under the hood.

That means you can simply launch a container using your favorite OS(e.g. Ubuntu) and install all the software that you want using the usual methods
"

So their perspective is "just install linux and do the whole she-bang by hand.

Which honestly sounds very dumb to me and like the people who make LXC container system don't understand what it is for ?!

Anyways....


Re-reading that thread I see that one year after I asked that, someone posted a link to "proxmox helper scripts"

https://tteck.github.io/Proxmox/

Code:
All Templates LXC
A script designed to allow for the creation of one of the many free LXC templates. Great for creating system LXCs.
The script creates a *.creds file in the Proxmox root directory with the password of the newly created LXC.
Please take note that if you plan to use this script for creating TurnKey LXCs, you'll need to modify the hostname after creation.
To create a new Proxmox VE Template LXC, run the command below in the Proxmox VE Shell.
bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/misc/all-templates.sh)"

Well that is promising !

Publishing "LXD" images ? (does that work on proxmox ?)
https://ubuntu.com/blog/publishing-lxd-images

list of lxc container images (can I use these AS IS in my proxmox server ?)
https://images.linuxcontainers.org/


And then I would like to make, one click deployable desktop (debian/ubuntu/mint/nixos/gentoo and probably others) CT containers with GPU support (novnc+virgl+passthrough) but that looks like another big can of worms
 
a container template is just the rootfs as tarball. you probably want to remove instance-specific information (things like users, home dirs, ssh host keys, machine-id, ..)

the lxc project has their own tool to generate such barebones tarballs called distrobuilder: https://github.com/lxc/distrobuilder
we have our own for Debian and Arch based distros: https://git.proxmox.com/?p=dab.git;a=summary / https://git.proxmox.com/?p=aab.git;a=summary

but you can also use something like debootstrap/mmdebstrap or the equivalent for other distros ;)

list of lxc container images (can I use these AS IS in my proxmox server ?)
https://images.linuxcontainers.org/

for the most part, yes. some of them might require manual fixups
 
I've come to the conclusion that it is easier to script the building of the LXC container from scratch
Rather than take a running system and make it deployable.

This is mostly because, you need to make the script no matter to what to build the first one.
Then you still need the script for updates
and lastly, there does not seem to be a universal way to do something akin to "sysprep" on window, that is to clean the distribution of all running files, keys, identifiers and other forensic. Trying to do that is more work than creating the build script.

I have been making such script, like I have just release a LXC build script for Vaultwarden


and a few weeks ago I made one for openwrt as a VPN client


And I have one for Stable Diffusion Automatic1111 WebUI , but it was the first one and not as nice as the later ones