Distrobox containers disappear on reboot

I have an application that I need to run in an ubuntu distrobox. I can create the distrobox and run it fine, but when I reboot, any created distroboxes are gone. I end up having to re-create it from scratch every time.

I’ve tried both creating them imperatively (putting distrobox in systemPackages) as well as using the home-manager module, but they disappear in both cases. In the home-manager module case, I’m not even sure how to force a container rebuild without doing a whole system rebuild (restarting distrobox-home-manager.service doesn’t do anything).

I am using docker backend.

I haven’t been able to figure out why I’m getting this behavior and searching hasn’t produce any other posts about this. Is this just a result of nixos not persisting containers, or is there a configuration error that I can fix?

That’s weird, my containers are still there when I reboot (created by distrobox or not). And I don’t even have distrobox installed in my system packages, I use it on the fly with Nix shell.

Do you use impermanence? Could you show your Nix docker configuration?

I don’t use Impermanence. this is all I have for docker config, which I believe I copied from the wiki at some point:

virtualisation.docker = {
      enable = true;
      enableOnBoot = true;
      autoPrune.enable = true;
    };

Looking at it now, do you think autoPrune could be the culprit?

Indeed, autoPrune is the culprit here.

In the service implementation, there’s three units involved:

  • the docker service, which runs the main service
  • the docker-prune service, which runs the pruning
  • the docker-prune timer, which runs on a weekly basis (by default, with autoPrune.dates)

docker-prune is configured to start after docker has started, using the After= systemd directive.

Since you set enableOnBoot, the docker service starts on boot, and effectively triggers the docker-prune service.

The pruning uses docker system prune -f, which can be configured with the --filter flag to exclude some containers from being pruned.

If you want to keep the autoPrune option, you can set this flag in virtualisation.docker.autoPrune.flags.

Thanks, I’ll just disable it for now and see how it goes.