NixOS Containers: Difference between revisions

imported>Onny
Additional example usage: List containers
imported>Onny
Updated nameserver workaround
Line 34: Line 34:
     system.stateVersion = "23.05";
     system.stateVersion = "23.05";


     networking.firewall = {
     networking = {
      enable = true;
      firewall = {
      allowedTCPPorts = [ 80 ];
        enable = true;
        allowedTCPPorts = [ 80 ];
      };
      # Use systemd-resolved inside the container
      useHostResolvConf = mkForce false;
     };
     };
 
   
     # Manually configure nameserver. Using resolved inside the container seems to fail
     services.resolved.enable = true;
    # currently
    environment.etc."resolv.conf".text = "nameserver 8.8.8.8";


   };
   };
Line 78: Line 80:


Further informations are available in the {{manual:nixos|sec=#ch-containers|chapter=NixOS manual}}.
Further informations are available in the {{manual:nixos|sec=#ch-containers|chapter=NixOS manual}}.
=== Troubleshooting ===
Configuring nameservers for containers is [https://github.com/NixOS/nixpkgs/issues/162686 currently broken]. Therefore in some cases internet connectivity can be broken inside the containers. A temporary workaround is to manually write the <code>/etc/nixos/resolv.conf</code> file like this:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
containers.nextcloud.config = { config, pkgs, ... }: {
  [...]
  environment.etc."resolv.conf".text = "nameserver 8.8.8.8";
};
</nowiki>}}


== Declarative docker containers ==
== Declarative docker containers ==