Search code examples
linuxdockerservernixnixos

How to run a docker container declaratively on nixos server?


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.


Solution

  • 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";
        };
      };
    }