Managing multiple instances of an app/service

Hey folks, looking into migrating one of my larger servers to NixOS and am stuck on something. In a few cases, I run multiple instances of a single app if I’m using it in distinct contexts (E.g. I have a Gitea instance for personal projects and another for a shared context where I have a few commercial and open source projects and other team members.) Some services support multiple instances while others don’t, and I’d rather not use an entirely separate server just for another Gitea when the first will do quite nicely. I’ve come up with a couple different approaches but I don’t like either all that much, and am wondering if there’s another option I haven’t considered or if I’m missing something in one of these?

Simplest would be using NixOS containers. I don’t necessarily want to manage coordinating a fleet of private IPs across each container, keeping them in sync, tracking which IP maps to which instance, etc. I’d also rather not do similar with ports if I can avoid it. Can I either:

  1. Use systemd network namespaces/isolation to give each container its own namespace on the host so each can bind its own port? I’m guessing this is what the private networking feature already does–I just didn’t know if isolation was capable of, say, letting each Gitea container have its own port 3000 somehow.
  2. Use networking shenanigans to give containers addresses via DHCP, then map back to their hostnames somehow?

The other option, of course, is to just use Podman/Docker and declarative container configs. I may ultimately go that route, but would rather stick closer to NixOS if possible.

Thanks a bunch.

in case it helps you out at all … nixos declarative containers, created with containers.<name>, automatically get an entry in your servers /etc/hosts file

if you had a caddy instance running on the server you could reference containers by http://name.containers:12345, for example

i hope that info provides at least some value to you

4 Likes

Ah, thanks, that does help some. Still wish I could assign addresses automatically but this will do for the moment–at least the IP is only in a single place.