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.
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.