NixOS Containers: Difference between revisions

m Change sub-headings-4 to bold paragraph
Line 55: Line 55:
By default, if <code>privateNetwork</code> is not set, the container shares the network with the host, enabling it to bind any port on any interface. However, when <code>privateNetwork</code> is set to <code>true</code>, the container gains its private virtual <code>eth0</code> and <code>ve-<container_name></code> on the host. This isolation is beneficial when you want the container to have its dedicated networking stack.
By default, if <code>privateNetwork</code> is not set, the container shares the network with the host, enabling it to bind any port on any interface. However, when <code>privateNetwork</code> is set to <code>true</code>, the container gains its private virtual <code>eth0</code> and <code>ve-<container_name></code> on the host. This isolation is beneficial when you want the container to have its dedicated networking stack.


===== NAT (Network Address Translation) =====
'''NAT (Network Address Translation)'''
 
In order to allow the container to connect to the internet, you have to configure NAT through <code>networking.nat</code>.
In order to allow the container to connect to the internet, you have to configure NAT through <code>networking.nat</code>.
{{File|3=networking.nat = {
{{File|3=networking.nat = {
Line 63: Line 64:
   # Lazy IPv6 connectivity for the container
   # Lazy IPv6 connectivity for the container
   enableIPv6 = true;
   enableIPv6 = true;
};|name=/etc/nixos/configuration.nix|lang=nix}}
};|name=/etc/nixos/configuration.nix|lang=nix}}'''Bridge'''


===== Bridge =====
Connect a container to a bridge using Network Manager interfaces:
Connect a container to a bridge using Network Manager interfaces:
{{File|3=networking = {
{{File|3=networking = {
Line 88: Line 88:
   localAddress = "192.168.100.5/24";
   localAddress = "192.168.100.5/24";
   config = { };
   config = { };
};|name=/etc/nixos/configuration.nix|lang=nix}}
};|name=/etc/nixos/configuration.nix|lang=nix}}'''Without privateNetwork (simpler)'''


===== Without privateNetwork (simpler) =====
If the service can be accessed by changing its port, the private network is not needed necessarily. Be careful to not use occupied ports. This example runs an [[Actual]] server on port 3003. It can be accessed through the host at <code>http://localhost:3003</code>. Since <code>privateNetwork</code> is not defined, it defaults to <code>false</code>.
If the service can be accessed by changing its port, the private network is not needed necessarily. Be careful to not use occupied ports. This example runs an [[Actual]] server on port 3003. It can be accessed through the host at <code>http://localhost:3003</code>. Since <code>privateNetwork</code> is not defined, it defaults to <code>false</code>.