3

I installed Docker 17.12.0-ce via Nix in Ubuntu (Linux uplink 4.13.0-36-generic #40~16.04.1-Ubuntu SMP Fri Feb 16 23:25:58 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux), but every time I try to execute any Docker command, it keeps telling me: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

This is what I did:

$ nix-env --install --prebuilt-only docker-17.12.0-ce

$ nix-env -q
docker-17.12.0-ce
go-1.9.4
hugo-0.32.2
kotlin-1.2.21
nix-1.11.16
nodejs-8.9.4
openjdk-8u172b02
openjdk-9.0.4-b11

$ docker version
Client:
 Version:   17.12.0-ce
 API version:   1.35
 Go version:    go1.9.4
 Git commit:    486a48d2701493bb65385788a291e36febb44ec1
 Built: Thu Feb 15 13:56:40 2018
 OS/Arch:   linux/amd64
 Experimental:  false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

$ docker ps -a
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I read the Post-installation steps for Linux (even though this shouldn't apply, to some extent, to Nix packages) and went ahead and added a docker user and all that stuff...but still, nothing.

I know there are tons of answers for this question — and I've tried several "solutions"...but no luck yet.

x80486
  • 5,131
  • 4
  • 32
  • 71
  • relog and/or restart – Alex Karshin Feb 24 '18 at 03:53
  • @AlexKarshin Indeed, I've done it — several times. – x80486 Feb 24 '18 at 03:56
  • 1
    Oh, okay, I know I always have this after pure docker installation and relogging helps – Alex Karshin Feb 24 '18 at 03:58
  • 1
    Are you on NixOS? If so, you should probably install docker via the NixOS module system instead of your user profile (`$ nix-env ...`). – Robert Hensing Feb 24 '18 at 11:07
  • Is the dockerd daemon running? – BMitch Feb 24 '18 at 11:15
  • @RobertHensing I forgot to put the operating system. I'm running Ubuntu — updated the question on that matter. I think the issue is that there is no Docker daemon running, as @BMitch pointed out. If I run `ps aux | grep docker` I don't see anything — but the output for the `grep` command itself. I was really expecting everything to just works after running `nix-env --install --prebuilt-only docker-17.12.0-ce`, as I do with other packages. I have no idea how to start that daemon, if I do `sudo service docker start` it tells me: `Failed to start docker.service: Unit docker.service not found`. – x80486 Feb 24 '18 at 13:48

1 Answers1

4

When you install packages on non-NixOS distros, services (such as daemons) are not set up. Services are created by NixOS modules, hence they require NixOS.

For example, in the case of Docker, the daemon is created by setting up a systemd service. Snippets from the NixOS module are shown below:

  ...
  options.virtualisation.docker = {
    enable =
      mkOption {
        type = types.bool;
        default = false;
        description =
          ''
            This option enables docker, a daemon that manages
            linux containers. Users in the "docker" group can interact with
            the daemon (e.g. to start or stop containers) using the
            <command>docker</command> command line tool.
          '';
};
...

systemd.services.docker = {
        wantedBy = optional cfg.enableOnBoot "multi-user.target";
        environment = proxy_env;
        serviceConfig = {
          ExecStart = [
            ""
            ''
              ${cfg.package}/bin/dockerd \
                --group=docker \
                --host=fd:// \
                --log-driver=${cfg.logDriver} \
                ${optionalString (cfg.storageDriver != null) "--storage-driver=${cfg.storageDriver}"} \
                ${optionalString cfg.liveRestore "--live-restore" } \
                ${cfg.extraOptions}
            ''];
          ExecReload=[
            ""
            "${pkgs.procps}/bin/kill -s HUP $MAINPID"
          ];
};
...

You may be able to accomplish the equivalent on other distros, but you'll have to create the service and config files manually.

Emmanuel Rosa
  • 9,167
  • 2
  • 10
  • 18
  • I was digging into #nixos (IRC) and that's what I've been told. But honestly, that package is of no (or little) use whatsoever on non-NixOS distros. Right now, `dockerd` cannot be run as root — it just can't find it. For instance, the `snap` version of Docker comes with everything you need to run Docker (for those distros that supports snappy, of course)...and that's how it's expected, IMO. – x80486 Feb 25 '18 at 19:09
  • 3
    You're right. Although `nix` is advertised as a package manager for Linux, and it is, what's not clarified is that some packages are designed for NixOS only. We really should clear this up. For what it's worth, as a general rule, applications/utilities work fine, but services do not because they require deeper integration with the underlying OS; An area `nix` does not get in to. – Emmanuel Rosa Feb 25 '18 at 22:58