lol

docker-rootless service: init

+150
+8
nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
··· 35 35 </listitem> 36 36 <listitem> 37 37 <para> 38 + <link xlink:href="https://docs.docker.com/engine/security/rootless/">rootless 39 + Docker</link>, a <literal>systemd --user</literal> Docker 40 + service which runs without root permissions. Available as 41 + <link xlink:href="options.html#opt-virtualisation.docker.rootless.enable">virtualisation.docker.rootless.enable</link>. 42 + </para> 43 + </listitem> 44 + <listitem> 45 + <para> 38 46 <link xlink:href="https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-overview.html">filebeat</link>, 39 47 a lightweight shipper for forwarding and centralizing log 40 48 data. Available as
+1
nixos/doc/manual/release-notes/rl-2205.section.md
··· 11 11 ## New Services {#sec-release-22.05-new-services} 12 12 13 13 - [aesmd](https://github.com/intel/linux-sgx#install-the-intelr-sgx-psw), the Intel SGX Architectural Enclave Service Manager. Available as [services.aesmd](#opt-services.aesmd.enable). 14 + - [rootless Docker](https://docs.docker.com/engine/security/rootless/), a `systemd --user` Docker service which runs without root permissions. Available as [virtualisation.docker.rootless.enable](options.html#opt-virtualisation.docker.rootless.enable). 14 15 15 16 - [filebeat](https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-overview.html), a lightweight shipper for forwarding and centralizing log data. Available as [services.filebeat](#opt-services.filebeat.enable). 16 17
+1
nixos/modules/module-list.nix
··· 1187 1187 ./virtualisation/oci-containers.nix 1188 1188 ./virtualisation/cri-o.nix 1189 1189 ./virtualisation/docker.nix 1190 + ./virtualisation/docker-rootless.nix 1190 1191 ./virtualisation/ecs-agent.nix 1191 1192 ./virtualisation/libvirtd.nix 1192 1193 ./virtualisation/lxc.nix
+98
nixos/modules/virtualisation/docker-rootless.nix
··· 1 + { config, lib, pkgs, ... }: 2 + 3 + with lib; 4 + 5 + let 6 + 7 + cfg = config.virtualisation.docker.rootless; 8 + proxy_env = config.networking.proxy.envVars; 9 + settingsFormat = pkgs.formats.json {}; 10 + daemonSettingsFile = settingsFormat.generate "daemon.json" cfg.daemon.settings; 11 + 12 + in 13 + 14 + { 15 + ###### interface 16 + 17 + options.virtualisation.docker.rootless = { 18 + enable = mkOption { 19 + type = types.bool; 20 + default = false; 21 + description = '' 22 + This option enables docker in a rootless mode, a daemon that manages 23 + linux containers. To interact with the daemon, one needs to set 24 + <command>DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock</command>. 25 + ''; 26 + }; 27 + 28 + setSocketVariable = mkOption { 29 + type = types.bool; 30 + default = false; 31 + description = '' 32 + Point <command>DOCKER_HOST</command> to rootless Docker instance for 33 + normal users by default. 34 + ''; 35 + }; 36 + 37 + daemon.settings = mkOption { 38 + type = settingsFormat.type; 39 + default = { }; 40 + example = { 41 + ipv6 = true; 42 + "fixed-cidr-v6" = "fd00::/80"; 43 + }; 44 + description = '' 45 + Configuration for docker daemon. The attributes are serialized to JSON used as daemon.conf. 46 + See https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file 47 + ''; 48 + }; 49 + 50 + package = mkOption { 51 + default = pkgs.docker; 52 + defaultText = literalExpression "pkgs.docker"; 53 + type = types.package; 54 + example = literalExpression "pkgs.docker-edge"; 55 + description = '' 56 + Docker package to be used in the module. 57 + ''; 58 + }; 59 + }; 60 + 61 + ###### implementation 62 + 63 + config = mkIf cfg.enable { 64 + environment.systemPackages = [ cfg.package ]; 65 + 66 + environment.extraInit = optionalString cfg.setSocketVariable '' 67 + if [ -z "$DOCKER_HOST" -a -n "$XDG_RUNTIME_DIR" ]; then 68 + export DOCKER_HOST="unix://$XDG_RUNTIME_DIR/docker.sock" 69 + fi 70 + ''; 71 + 72 + # Taken from https://github.com/moby/moby/blob/master/contrib/dockerd-rootless-setuptool.sh 73 + systemd.user.services.docker = { 74 + wantedBy = [ "default.target" ]; 75 + description = "Docker Application Container Engine (Rootless)"; 76 + # needs newuidmap from pkgs.shadow 77 + path = [ "/run/wrappers" ]; 78 + environment = proxy_env; 79 + unitConfig.StartLimitInterval = "60s"; 80 + serviceConfig = { 81 + Type = "notify"; 82 + ExecStart = "${cfg.package}/bin/dockerd-rootless --config-file=${daemonSettingsFile}"; 83 + ExecReload = "${pkgs.procps}/bin/kill -s HUP $MAINPID"; 84 + TimeoutSec = 0; 85 + RestartSec = 2; 86 + Restart = "always"; 87 + StartLimitBurst = 3; 88 + LimitNOFILE = "infinity"; 89 + LimitNPROC = "infinity"; 90 + LimitCORE = "infinity"; 91 + Delegate = true; 92 + NotifyAccess = "all"; 93 + KillMode = "mixed"; 94 + }; 95 + }; 96 + }; 97 + 98 + }
+1
nixos/tests/all-tests.nix
··· 104 104 dnscrypt-wrapper = handleTestOn ["x86_64-linux"] ./dnscrypt-wrapper {}; 105 105 doas = handleTest ./doas.nix {}; 106 106 docker = handleTestOn ["x86_64-linux"] ./docker.nix {}; 107 + docker-rootless = handleTestOn ["x86_64-linux"] ./docker-rootless.nix {}; 107 108 docker-edge = handleTestOn ["x86_64-linux"] ./docker-edge.nix {}; 108 109 docker-registry = handleTest ./docker-registry.nix {}; 109 110 docker-tools = handleTestOn ["x86_64-linux"] ./docker-tools.nix {};
+41
nixos/tests/docker-rootless.nix
··· 1 + # This test runs docker and checks if simple container starts 2 + 3 + import ./make-test-python.nix ({ lib, pkgs, ...} : { 4 + name = "docker-rootless"; 5 + meta = with pkgs.lib.maintainers; { 6 + maintainers = [ abbradar ]; 7 + }; 8 + 9 + nodes = { 10 + machine = { pkgs, ... }: { 11 + virtualisation.docker.rootless.enable = true; 12 + 13 + users.users.alice = { 14 + uid = 1000; 15 + isNormalUser = true; 16 + }; 17 + }; 18 + }; 19 + 20 + testScript = { nodes, ... }: 21 + let 22 + user = nodes.machine.config.users.users.alice; 23 + sudo = lib.concatStringsSep " " [ 24 + "XDG_RUNTIME_DIR=/run/user/${toString user.uid}" 25 + "DOCKER_HOST=unix:///run/user/${toString user.uid}/docker.sock" 26 + "sudo" "--preserve-env=XDG_RUNTIME_DIR,DOCKER_HOST" "-u" "alice" 27 + ]; 28 + in '' 29 + machine.wait_for_unit("multi-user.target") 30 + 31 + machine.succeed("loginctl enable-linger alice") 32 + machine.wait_until_succeeds("${sudo} systemctl --user is-active docker.service") 33 + 34 + machine.succeed("tar cv --files-from /dev/null | ${sudo} docker import - scratchimg") 35 + machine.succeed( 36 + "${sudo} docker run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10" 37 + ) 38 + machine.succeed("${sudo} docker ps | grep sleeping") 39 + machine.succeed("${sudo} docker stop sleeping") 40 + ''; 41 + })