Replacing docker-compose with NixOS

I’m looking to deploy a few microservices to run a webapp, your typical sort of setup, with a database, backend and frontend; I’d like to put these in a separate network, allow them to talk to one another, and forward networking as I see fit. In other words, I want to do something like what docker-compose does, but in a Nixy way.

My motivation is a desire to have a super simple framework for deploying webapps. I would like to run a NixOS host with some boilerplate services (for authentication, DNS, maybe secret management, for example), and run a bunch of different apps on it.

I noticed Arion is one option, which is literally a docker-compose wrapper. There is also Disnix although I am not entirely sure if its suitable for this purpose. Both projects seem maintained, but don’t seem to have very wide adoption, so its hard to tell how easy it will be to pick them up.

These days NixOS also has plenty of Kubernetes options and specifically a very interesting addon system allowing Kubernetes operators to be defined in the configuration. However, Kubernetes seems like serious overkill at this point, and the learning curve is hefty.

  1. What’s your take on these options? Pros/Cons? Experience?
  2. Are there other options? Jerry-rigged NixOS containers with virtual networking? Witchcraft?
  3. Can you share examples of how you deploy setups like this?
11 Likes

Also check out docker-containers. This option allows you to declare containers in a very similarly manner to docker-compose and NixOS turns them into easily managable systemd services for you.

1 Like

I am familiar with this option, what I am wondering is how could I network a group of such containers together.

docker-containers.<name>.extraDockerOptions uses --network=... as its canonical sample value, so the missing piece would be to automate the Docker network creation declaratively, perhaps through a systemd unit.

1 Like

I followed along this blog post in starting a similar project, which relies on the mentioned docker-containers. It utilizes one-shot systemd services to create networks, and has worked pretty smoothly thus far.

5 Likes

Thanks, this is exactly what I was looking for :slight_smile: