I have some doubts regarding the docker installation.
I have installed docker in rootless mode via:
virtualisation.docker.rootless = {
enable = true;
setSocketVariable = true;
};
which is mentioned in Docker - NixOS Wiki
but this doesn’t start the docker daemon by default. I have to do these imperative commands for it to work:
systemctl --user enable --now docker
systemctl --user start docker
systemctl --user status docker #to check the status
my doubt:
I want to know whether I can avoid this imperative method and make the docker daemon starts running and make the docker daemon run on boot too right after I switched to the new nixos configuration .
You could wrap these commands in a dedicated service
, smth like this:
# not tested
systemd.services.start-docker = {
wantedBy = [ "multi-user.target" ];
requires = [
"docker.service"
];
after = [
"docker.service"
];
script = ''
systemctl --user enable --now docker
systemctl --user start docker
systemctl --user status docker #to check the status
'';
serviceConfig = {
Type = "oneshot";
};
};
where can i see the documentation for this option?
coz I couldn’t get what does the attributes like wantedBy, requires, after, script, serviceConfig actually does with examples
Thanks a lot.
But I wonder why it doesn’t get added automatically like all nixos configuration options work by default.
It’s just designed that way I’d guess?
In your use case you want to start as soon as the device / system has started, that may not be the case for everyone.
So you need to “explicitly” start the service
1 Like
Makes sense.
But I wanted docker to be used inside a nix-shell -p command for just a one shot. But it didn’t start the daemon when invoked as a shell and requires manually starting it in host. So I thought the behaviour is different