Extra-container - Run declarative containers without full system rebuilds


#1

Example:

sudo extra-container create --start <<'EOF'
{
  containers.demo = {
    privateNetwork = true;
    hostAddress = "10.250.0.1";
    localAddress = "10.250.0.2";

    config = { pkgs, ... }: {
      networking.firewall.allowedTCPPorts = [ 50 ];

      systemd.services.hello = {
        wantedBy = [ "multi-user.target" ];
        script = "while true; do echo hello | ${pkgs.netcat}/bin/nc -lN 50; done";
      };
    };
  };
}
EOF

curl 10.250.0.2:50 # Returns 'hello' from the container

#2

This is awesome!
Other than that, I’m playing around with it already and writing some containers that I’ll use instead of docker-compose or nixos-shell. Given that it’s using a super solid foundation I don’t think there’ll be any issues, but that’s just what we needed.
Thank you very much!

(removed ignorant comment about list missing)


#3

Also update action is missing. Do I have to destroy/add/start each time configuration changes?


#4

@danbst, no, just run extra-container create --restart with an updated config. Or use --start to start the container even if it’s not already running.
But note that this doesn’t clear the contents of the container directory in /var/lib/containers/. Would this be required for your use case?


#5

How does this differ from NixOps with a container backend?


#6

@manveru, your comment wasn’t ignorant at all, I forgot to document the list command. It’s fixed in the latest update.


#7

@tom, the NixOps container backend uses imperative containers which lack some options of declarative containers.


#8

Perhaps add this as another nixops target/option? I’m seeing a period of rapid progress of experimentation and think the community should try to consolidate and mature some tools before it becomes too fragmented.


#9

I think this should be integrated into nixos-container so that there’s feature parity between imperative and declarative containers. There are a few kinks left to work out, then I’ll open an issue.


#10

I had success with running declarative containers with this piece of software on non-NixOS (Ubuntu). I’ve documented problems in https://github.com/erikarvstedt/extra-container/issues/1

That’s really awesome!