NixOS Containers: Difference between revisions

imported>Alyaeanyx
m Add warning and improve formatting
imported>Onny
Add troubleshooting section for native NixOS containers
Line 2: Line 2:


It is possible to configure native systemd-nspawn containers, which are running NixOS and are configured and managed by NixOS using the <code>containers</code> directive.
It is possible to configure native systemd-nspawn containers, which are running NixOS and are configured and managed by NixOS using the <code>containers</code> directive.
=== Installation ===


The following example creates a container called <code>nextcloud</code> running the web application [[Nextcloud]]. It will start automatically at boot and has its private network subnet.
The following example creates a container called <code>nextcloud</code> running the web application [[Nextcloud]]. It will start automatically at boot and has its private network subnet.
Line 38: Line 40:


In order to reach the web application on the host system, we have to open [[Firewall]] port 80 and also configure NAT through <code>networking.nat</code>.
In order to reach the web application on the host system, we have to open [[Firewall]] port 80 and also configure NAT through <code>networking.nat</code>.
=== Usage ===


Checking the status of the container
Checking the status of the container
Line 61: Line 65:


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 ==