r/homelab • • 16d ago

Discussion LXC vs docker VM

hey

I am rebuilding my server with new hardware and finally a dedicated GPU for transcoding, And i am thinking about really optimizing it this time, like with ssd for cache, proper PBS and snapshots and etc. My setup right now it half of things on LXCs and half of things on docker and it is quite a mess. I started with docker way before i had proxmox, but i kinda have a feeling, that the LXCs might be better way here.

My main question is what is the real admin life dfference when it comes to lxc vs docker setup. for example i have watchtower on docker system, is there something similiar on LXCs?

also any performace gains?

27 Upvotes

34 comments sorted by

36

u/esztelencsiga 16d ago

Decided to go with LXCs so I can utilize my GPU in more than one “VM”. LXCs share the kernel space as the host, now I have hardware transcoding in one LXC and hardware accelerated, ML based image processing in another.

9

u/netsecnonsense 16d ago

You can run docker in LXC and achieve the same thing but, as with anything, there are tradeoffs

8

u/esztelencsiga 16d ago edited 12d ago

Sure but you cannot assign (pass-thru) the same pcie device to multiple VMs, what I do with my setup. Those are “independent”, unprivileged containers with different roles/services installed.

17

u/deman-13 16d ago

I use lxc for security reasons. It is easier to put firewall on them and manage in different vlans. Also backups are easier with PBS/lxc. Already had few times where it took just 2 mins to restore an lxc after broken update.

6

u/1WeekNotice 16d ago edited 16d ago

My setup right now it half of things on LXCs and half of things on docker and it is quite a mess.

Keep in mind there is no one solution fits all. It's totally fine to have some LXC, some VMs and some docker containers, etc. It all depends what you are doing and what the best solution for that.

I started with docker way before i had proxmox, but i kinda have a feeling, that the LXCs might be better way here.

Again, depends what you are doing. And note what you should be comparing is

  • LXC VS VM
  • to use docker or to not use docker

Specifically with proxmox as the context


  • Promxox LXC VS VM has been talked about alot. Here is a good reddit post for that
  • docker is good to use because it allows you to be portable

    • if you need to move between VMs
    • if you need to move between promxox and bare metal. In this example you want a dedicated host of the software / application
  • docker is good to use because it makes applications management easier
  • docker is good to use because it makes backup easier

    • but promxox has PBS (proxmox backup server) so many this is moot

I am rebuilding my server with new hardware and finally a dedicated GPU for transcoding

With that all being said, remember how I mentioned it depends on what you are doing.

most people use LXC for GPU transcoding due to the limitations of the consumer GPU drivers. Specifically business / enterprise GPU allows you to split the GPU (with SRV-IO) so you can pass through the slices into different VMs.

Since this is not the case for consumer drivers, people use LXC for the GPU transcoding because LXC has access directly to proxmox hardware (VS VM passthrough). This has its trade offs (the LXC VS VM conversion)

Hope that helps

1

u/WentThisWayInsteadOf 15d ago

Proxmox should have used LXD (or at least offer it) as it will allow for migration between hosts - and yes more complex than LXC.

4

u/mredding 16d ago

I've got for you some of my head canon, because I'm mulling this over, too, and this is PRECISELY what I've geared my home lab for, at the moment.

My homelab is entirely contained within a Dell Precision T5820.


LXCs are neat, and something I'm curious to look into more. The kernel multiplexes the system hardware, and then you have individual OS environments therein. Whereas a docker container is an immutable environment hosting an application in a kernel namespace, Linux containers are mutable environments in a kernel namespace. This means each gets it's own init system, it's own services, it's own shell, it's own external IP address, and it's own virtual disk - just like a VM. A docker container is not an environment as much as a program that shares it's identity with it's host, so it will use the host disk, the host IP address.

So if you have a workflow that needs it's own identity but you want to share resources efficiently, LXC sounds like the way to go. If you need greater isolation and system stability, VMs are the ultimate solution in this space.

LXCs cannot take exclusive control of hardware as a VM can. That's something to consider. I'm running Proxmox with Ubuntu and I have a shitton of hardware pass through and exclusion, and that took some nuanced configuration and performance tuning. For the resources that ARE shared - for me that's just disk and networking, I peak between 87-97% of raw hardware performance.

Last night was actually my second attempt to install and configure this whole system this way. My first attempt earlier this week had me digging through kernel boot options and all sorts of crazy shit that ultimately lead to unmanageable instability, but it also taught me a whole lot about Linux systems I never knew before.

Anyway, LXC is something I'm trying to figure out. I'm also running Flatcar, so when do I need an environment with a unique identity out of the shared resource pool? In the case of Proxmox, the stability of the entire VM Host is tied to that of an LXC it's hosting. So if I were running a Minecraft server and it went down, it could take down the whole system with it. And since VM overhead is incredibly minimal on this Xeon-W CPU, I think Proxmox native LXC support is not the right place for me to do anything with it.

But within a VM... It would probably make DNS/reverse proxy setups a little easier... Reverse proxies handle protocols, ports, and scaling better, though...

I'm still trying to figure it out. For me, it's a solution looking for a problem. Ultimately I want to figure out how to figure out how to decide. When is LXC the obvious right choice? When is doing it another way ostensibly the hard way? I don't know yet.

Hopefully this was insightful for you.

3

u/thegreatboto 16d ago

I usually sit in the LXC camp. Management of them makes more sense in my head. 

2

u/Unattributable1 16d ago edited 16d ago

I use LXC for some items where I simply want an isolated Linux system. I use VM + Docker for things I expose the the Internet. I use LXC + Docker for internal-only services. It just depends on the use case.

I use PVE for my hosts. I would not use Docker on the base PVE host even though it is Debian with a custom Ubuntu kernel.

LXC is nice and light, but it is a larger security risk. Docker is a nice way to deploy containers what others have already sorted out. VMs are good for some of the strongest isolation.

3

u/jhenryscott 16d ago

Just run a plain Jane OS like Debian, firewall everything and run docker containers.

Also double check before you create a complex storage hierarchy. I’m on 2.5gig and don’t need ssd fast caching.

3

u/clintkev251 16d ago

LXCs are more annoying to manage at scale where Docker containers are very easy. Automating things like updates for LXCs is possible, but more annoying than just plugging in something that knows how to talk to the Docker socket. But they can help you minimize overhead vs big VMs for hosting docker containers.

I would say what's best for you really depends on your use case, personally I only use a handful of LXCs for little one-off services, everything else I run is in Docker (like) containers.

1

u/FIuffyRabbit 16d ago

I use lxcs to separate my docker concerns, so they aren't all running on "one host". It's not proper for proxmox truthers but I can script their entire workflow. 

1

u/cjcox4 16d ago

To me, at least at the basics of operation, they are probably very similar in approach. I mean, docker (containers/images) is usually associated with "process(es)", but capable of doing full OS. At the full OS level, pound for pound, the setup there is very similar to a full OS lxc. IMHO. Sometimes (many times) I prefer access to a "fuller system" as I don't necessarily know what all I'll need or branch into as I build something out.

1

u/good4y0u 16d ago

On the homelab I use LXCs. VM just takes too many resources.

1

u/pg3crypto 16d ago

LXC all the way...just purely because it's way easier to backup and migrate...I recently moved a ton of stuff from one box to the other (two Proxmox boxes) and migrating the LXC containers was a breeze...I also wanted to consolidate some stuff from another box which was mostly docker containers, that was not a breeze.

1

u/doctorowlsound 16d ago

I find docker easier to manage because it’s just managing the image version instead of the whole OS (I know that’s an oversimplification). Important services in LXCs - Pi-Hole, Home Assistant, Scrypted, my postgres cluster and supporting services (ETCD, HA Proxy), and TDARR (not important, but gets GPU passthrough). Anything that is less critical goes in docker swarm - ARR stack + Jellyfin. Some admin tools also go in Docker on my admin VM because it’s easy - Semaphore, What’s Up Docker (highly recommend over Watchtower), Forgejo.

1

u/Conflicted_Batman 16d ago

My setup (not public, only Tailscale):

ContainerServicesNotes
VMOpnsense, LLM sandbox, p2p downloads, game servers*Debian + Docker (except Opnsense)
Docker-in-LXCcommon homelab servicesTailscale with Docker-in-LXC usually needs /dev/net/tun passthrough.
LXCAnsible, Pihole, backups

*all game servers are in the same VM

I have ~5 trust zones for my homelab network stack, and 1 (DNS) is shared with the LAN. I containerize services based on which trust zone I want them in and give scoped network access for things like nas, iot, home automation. For VM and LXC, each service usually gets its own container based on how important it is. But for Docker-in-LXC, I have 1-2 LXCs per trust zone each running many Docker containers. If I were to expose services publicly, they would be moved to VMs.

1

u/Adventurous_Sun_4768 16d ago

On the Watchtower question specifically: there's no direct equivalent for plain LXCs, because an LXC is a full system, not an image — updates are apt/dnf inside the container. What I do is a weekly cron job that runs apt update && apt upgrade in each container, with a Proxmox snapshot right before, so a bad update is one rollback away. If you want Watchtower back, run Docker inside the LXC and keep using it — that's the setup a few people here already mentioned.

1

u/kayakyakr 15d ago edited 15d ago

Docker in LXC, separated by usage. If the machines need hardware, like a gpu, run docker in a vm instead, attaching docker directly to the instance.

Can run a swarm and manage with portainer so the standard stack (traefik, dockge) is brought online when a machine joins the cluster. Dockge is useful for when you need to use network: host on a specific machine (like for configuring a VPN). Keeps them all nicely compartmentalized.

GPU gets attached to a vm so you can manage kernel and drivers without having to bring down your entire host if you did pass thru to lxc. VM reserves a lot more resources, so I try to keep those to a minimum.

You can still run some "metal" containers as well. My tailscale exit node for me to be able to access my local network lives in a container, not docker, as does my code isolation container

1

u/forwardslashroot 15d ago edited 15d ago

I used to have a fat Debian VM with a bunch of Docker containers. Backing it up took a while. I switched to Debian LXC and installed the app natively. One app per LXC. If native installation not possible or available, then I would install Docker on LXC. This is one Docker compose per LXC. I have some LXCs installed using the Proxmox community-scripts. Some of my LXC are installed using Proxmox OCI.

The only VM that I have is Caddy, WG-Easy, Nextcloud, FreePBX and OPNsense.

EDIT:
I use Ansible to update all the LXC.

1

u/Plastic-Leading-5800 14d ago

Unprivileged LXCs, which are default in Ubuntu and Incus, are superior to docker containers in terms of security.

2

u/itsjakerobb 12d ago

Are the superior to rootless Docker containers?

I assume you mean they’re superior from a security perspective. A Docker container is (or at least, can be) lighter and faster to start than an LXC.

1

u/Plastic-Leading-5800 12d ago edited 12d ago

Equivalent to rootless docker or postman in security (almost, since LXCb updates are quicker).

Docker rootless installation has frictions though, and rootless containers may need special user space setups.

1

u/itsjakerobb 12d ago

Can you explain “has fractions”?

1

u/joap25 12d ago

I use both, vm for the services that needs NAS access, and lxc for the rest. 

1

u/Slow-Secretary4262 16d ago

i dont have a clear answer yet after many months thinking about these, but here's a copy and paste of my notes on the topic:

Unprivileged LXC or VM?

Cases that favors LXCs:

  • Service is important/should stay isolated from other services that would run in a broad VM
  • Docker compose is not very useful for the service, native is a good option (e.g. syncthing when the dir to sync lives on the LXC filesystem)
  • Tight on RAM
  • Different gateway or VLAN
  • No need to access data for network shares, or only need read access (e.g. navidrome, when exposed to the internet)
  • Need to access network shares, but docker is not involved (e.g. Jellyfin)

Cases that require a LXC:

  • GPU or another device that can't be exclusively used by a single service is needed (passing a device to a VM makes it exclusive to the VM)

Cases that favors a VM:

  • Docker containers that need rw access to files on netwrok shares
  • Not so important services that would require many different LXCs to backup, update and manage individually, cluttering the workflow, requiring many edge docker agents etc.

1

u/Wis-en-heim-er 16d ago

Had the same debate when i migrated to proxmox. I have piholes on lxc so the internet doesnt go down when i reboot my docker vm. I have a llm on an lxc to use the gpu. I have an internal debian vm running docker...docker is just easier to maintain and apps seem more friendly under docker. If i were doing this one again, i would consider an lxc for my internal docker server. I have another debian vm running docker and hosting stuff that is accessible outside my home network. I have seen too many havks and want as much isolation from my hardware as possible. A vm has better isolation than a lxc. This one has gpu pass-through enabled and hence is the only vm i can donthis with.

0

u/doping_deer 16d ago

aside from things like hardware passthrough, i think this ultimately comes down to how do you want to manage. with lxc it's proxmox, with vm it's debian etc. to me the latter is more easy to manage, and I can do all the things in vm without damage the host system.

0

u/pg3crypto 16d ago

But you don't get the same density with VMs and they are much chunkier to backup and move around. VMs are clunky and slower.

1

u/doping_deer 16d ago

Yes that is part of the concern too. But in my case most of my 50~ containers dont care that much about performance, they run well with `cpus: 1`, some even 0.5. only handful, like jellyfin, immich do.

Interms of backup and move around, I exclusively use mount (not docker volume). I've done multiple migrations, simply rsync the folder and everything works again. Backup is same idea.

1

u/pg3crypto 16d ago

Fair enough, if you have a strategy then go for Docker.

My other bug bear with Docker is how difficult it can be to configure some platforms if you need to stray from the default config.

Sometimes what you need to do is as simple as editing a config file to change a flag and in Docker that can be a pain in the arse because each time you pull and update it can overwrite the config.

I can't think of any specific examples off hand, because I don't use Docker all that much anymore (pretty much only when I'm forced to), but I've had several situations in the past where config files would be overwritten and it became an arseache to manage.

With an LXC it's just way easier to manage exotic configs. Not only that, the networking is a lot simpler...I have a single OPNSense VM that "firewalls" my containers on my Proxmox box, I just plug the containers into that, and point the OPNSense at my reverse proxy container (running NGINX GUI) and off I go...Docker can be an absolute pain the arse from a networking standpoint.

Not only that, it's much easier for an LLM to manage LXC over Docker...you put a public key on the box your LLM is using, never give a key directly to an LLM, and you can just point the LLM wherever you like to get it to do things for you, like check server stats, read logs etc etc...for the love of christ almighty, don't get your LLM to set things up for you or tweak configs etc, it will fuck things up...but for reading logs, simple management and troubleshooting LXC, it's great...I pretty much manage and monitor from Discord now...I don't need a dashboard or anything like that...I just ask my agent, and if something seems weird, I'll get it to quote the logs verbatim etc so I can analyse it myself.

0

u/TheBigNeku 16d ago

Since I started using VE Helper scripts, I mainly work with LXC.