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.

4

1 回答 1

4

在非 NixOS 发行版上安装软件包时,不会设置服务(例如守护程序)。服务由 NixOS 模块创建,因此它们需要 NixOS。

例如,对于 Docker,守护进程是通过设置 systemd 服务来创建的。NixOS模块的片段如下所示:

  ...
  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"
          ];
};
...

您可能能够在其他发行版上完成等效操作,但您必须手动创建服务和配置文件。

于 2018-02-25T13:20:28.050 回答