Docker: Difference between revisions

Aos (talk | contribs)
m Use official nix search options
Onny (talk | contribs)
Merge Docker/Podman documentation in here
Line 1: Line 1:
[https://docker.com Docker] is a utility to pack, ship and run any application as a lightweight container.  
[https://docker.com Docker] is a utility to pack, ship and run any application as a lightweight container.  


== Installation ==
== Setup ==


To install docker, add the following to your NixOS configuration:
To install docker, add the following to your NixOS configuration:
Line 64: Line 64:
</syntaxHighlight>
</syntaxHighlight>


See [https://search.nixos.org/options?from=0&size=50&sort=alpha_asc&query=virtualisation.oci-containers oci-containers] for further options.
A more advanced example<syntaxhighlight lang="nixos">
{ 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\""
      ];
    };
  };
}
</syntaxhighlight>See [https://search.nixos.org/options?from=0&size=50&sort=alpha_asc&query=virtualisation.oci-containers oci-containers] for further options.
 
== Usage ==
NixOS uses Podman to run OCI containers. Note that these are '''user-specific''', so running commands with or without sudo can change your output.
 
List containers<syntaxhighlight lang="console">
# podman ps
</syntaxhighlight>Update image<syntaxhighlight lang="console">
# podman restart hackagecompare
</syntaxhighlight>List images<syntaxhighlight lang="console">
# podman ls
</syntaxhighlight>Remove container<syntaxhighlight lang="console">
# podman rm hackagecompare
</syntaxhighlight>Remove image<syntaxhighlight lang="console">
# podman rmi c0d9a5f58afe
</syntaxhighlight>Update image<syntaxhighlight lang="console">
# podman pull chrissound/hackagecomparestats-webserver:latest
</syntaxhighlight>Run interactive shell in running container<syntaxhighlight lang="console">
# podman exec -ti $ContainerId /bin/sh
</syntaxhighlight>


== Creating images with Nix ==
== Creating images with Nix ==