NixOS Containers: Difference between revisions

From NixOS Wiki
imported>Nix
m add Server category
imported>Nix
add more see also references
Line 35: Line 35:
== See also ==
== See also ==


{{manual:nixos|sec=#ch-containers|chapter=Chapter on Container Management}}
* {{manual:nixos|sec=#ch-containers|chapter=Chapter on Container Management}}
* [https://blog.beardhatcode.be/2020/12/Declarative-Nixos-Containers.html Blog Article - Declarative NixOS Containers]
* [https://discourse.nixos.org/t/extra-container-run-declarative-containers-without-full-system-rebuilds/511 NixOS Discourse - Extra-container: Run declarative containers without full system rebuilds]
* [https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/virtualization/nixos-container/nixos-container.pl Nixpkgs - nixos-container.pl]
* [https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/nixos-containers.nix Nixpkgs - nixos-containers.nix]


[[Category:Server]
[[Category:Server]]
[[Category:NixOS]]

Revision as of 03:06, 27 September 2021

There's not much to read here. Look at NixOS Manual, the upstream documentation on containers meanwhile.

Declarative docker containers

Example config:

 { config, pkgs, ... }:
 {
   config.virtualisation.oci-containers.containers = {
     hackagecompare = {
       image = "chrissound/hackagecomparestats-webserver:latest";
       ports = ["127.0.0.1:3010:3010"];
       volumes = [
         "/root/hackagecompare/packageStatistics.json:/root/hackagecompare/packageStatistics.json"
       ];
       cmd = [
         "--base-url"
         "\"/hackagecompare\""
       ];
     };
   };
 }

Troubleshooting

I have changed the host's channel and some services are no longer functional

Symptoms:

  • Lost data in PostgreSQL database
  • MySQL has changed its path, where it creates the database

Solution

If you did not have a system.stateVersion option set inside your declarative container configuration, it will use the default one for the channel. Your data might be safe, if you did nothing meanwhile. Add the missing system.stateVersion to your container, rebuild, and possibly stop/start the container.

See also