Home > other >  How to run a docker container declaratively on nixos server?
How to run a docker container declaratively on nixos server?

Time:08-02

How do I run a docker container declaratively on nixos server ? I am trying to run whoogle on a nix server and I don't wish to manually restart the whoogle container everytime I restart the server.

CodePudding user response:

  1. Use --restart always with docker command at initial start

  2. enable docker service to start at boot

And your container will start at boot

CodePudding user response:

After bit of guidance from the r/nixos community settled with this.

{ config, pkgs, ... }:

let
  host = "mydomain";
in
{
  virtualisation = {
    podman = {
      enable = true;
      dockerCompat = true;
    };
    oci-containers = {
      backend = "podman";
      containers.whoogle-search = {
        image = "benbusby/whoogle-search";
        autoStart = true;
        ports = [ "8080:5000" ]; #server locahost : docker localhost
      };
    };
  };
  services.nginx.virtualHosts = {
    "search.${host}" = {
      enableACME = true;
      forceSSL = true;
      locations."/".proxyPass = "http://localhost:8080";
    };
  };
}
  • Related