Linux NixOs Podman

Overview

Documenting how I switched from Docker to Podman in NixOs.

Enabling Podman on NixOS

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
		  # Virtualization / Containers
	  virtualisation.containers.enable = true;
	  virtualisation = {
	    podman = {
	      enable = true;
	      # Create a `docker` alias for podman, to use it as a drop-in replacement
	      dockerCompat = true;
	      # Required for containers under podman-compose to be able to talk to each other.
	      defaultNetwork.settings.dns_enabled = true;
	    };
	  };

...

	  environment.systemPackages = with pkgs; [
        ...
	    podman
        podman-compose
        ...
      ];

Define Registries

Podman needs to know in which registry to fetch the base images that we will use. To do so we have to set the list of registries in ~/.config/containers/registries.conf.

Set Default Folders

  1. storage.driver This specifies the storage driver used for containers. Common options include “zfs” for ZFS file system, or “dir” for using a directory.
  2. storage.graphroot Defines the root directory where container image layers are stored. This directory will contain the root file systems of the images themselves.
  3. storage.runroot Specifies the root directory where containers’ runtime data (like their root file systems, and log files) are stored. This directory might also be used to store configuration and state data.
  virtualisation.containers.storage.settings = {
    storage = {
      driver = "dir";
      graphroot = "/var/lib/containers/storage";
      runroot = "/var/containers/data";
    };
  };
1
podman run -d -p 8000:8000 -p 9000:9000 -p 9443:9443 --name portainer --restart=always --privileged -v /run/podman/podman.sock:/var/run/docker.sock -v /var/containers/data/portainer:/data portainer/portainer-ce:sts

References

Sample