13

I am running Ubuntu with the following docker software installed:

$ docker version
Client:
 Version:      1.9.1
 API version:  1.21
 Go version:   go1.4.3
 Git commit:   a34a1d5
 Built:        Fri Nov 20 17:56:04 UTC 2015
 OS/Arch:      linux/amd64
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

$ docker-compose -v
docker-compose version 1.7.0, build 0d7bf73

When trying to run docker-compose I am getting the following error:

$ sudo docker-compose up
ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

I have tried the following:

systemctl unmask docker.service
systemctl unmask docker.socket
systemctl start docker.service

sudo service docker status
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2016-04-29 13:36:57 CEST; 4min 3s ago
     Docs: https://docs.docker.com
 Main PID: 6394 (docker)
   Memory: 13.3M
      CPU: 119ms
   CGroup: /system.slice/docker.service
           └─6394 /usr/bin/docker daemon -H fd://

Apr 29 13:36:57 Charles docker[6394]: time="2016-04-29T13:36:57.722083467+02:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon opt...d IP address"
Apr 29 13:36:57 Charles docker[6394]: time="2016-04-29T13:36:57.805189862+02:00" level=warning msg="Your kernel does not support swap memory limit."
Apr 29 13:36:57 Charles docker[6394]: time="2016-04-29T13:36:57.827955299+02:00" level=info msg="Loading containers: start."
Apr 29 13:36:57 Charles docker[6394]: time="2016-04-29T13:36:57.828083895+02:00" level=info msg="Loading containers: done."
Apr 29 13:36:57 Charles docker[6394]: time="2016-04-29T13:36:57.828095512+02:00" level=info msg="Daemon has completed initialization"
Apr 29 13:36:57 Charles docker[6394]: time="2016-04-29T13:36:57.828125198+02:00" level=info msg="Docker daemon" commit=a34a1d5 execdriver=native-0.2 graphdriver=aufs version=1.9.1
Apr 29 13:36:57 Charles systemd[1]: Started Docker Application Container Engine.
Apr 29 13:37:10 Charles systemd[1]: Started Docker Application Container Engine.
Apr 29 13:37:34 Charles systemd[1]: Started Docker Application Container Engine.
Apr 29 13:38:01 Charles systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
anton@Charles:~/Documents/software/deliverable$ docker ps
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

Sudo?

When I run using sudo docker seems to be running:

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
$ docker ps
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

How can I fix this?

Magick
  • 4,603
  • 22
  • 66
  • 103
  • Is the Docker daemon indeed running? What do you get when you execute `docker version` (that also lists the daemon version, i.e. more details than `docker -v`)? – Rick Apr 29 '16 at 11:21
  • Can you verify that using `systemctl` or whatever service manager you're using? – Rick Apr 29 '16 at 11:25
  • Seems like that makes this a duplicate of http://stackoverflow.com/q/33562109/2137833 – Rick Apr 29 '16 at 11:28
  • Possible duplicate of [Can't connect to docker from docker-compose](http://stackoverflow.com/questions/29101043/cant-connect-to-docker-from-docker-compose) – Gangaraju Apr 29 '16 at 11:35
  • This is not a duplicate, as the other posts are using a different OS. Also, the proposed solutions did not solve this issue. – Magick Apr 29 '16 at 11:45
  • So, the daemon is running, but you cannot connect to it. Are you in the `docker` user group, just like they propose in my mentioned duplicate? You can check that by executing `groups` on your shell. – Rick Apr 29 '16 at 11:51
  • Yes. `$ groups anton adm sudo lpadmin sambashare docker` – Magick Apr 29 '16 at 11:54
  • If it _does_ work with sudo, this still sounds like a group issue... – Rick Apr 29 '16 at 12:00
  • Yes, and logging out and back in fix it. Thanks Rick. – Magick Apr 29 '16 at 12:05
  • What are the permissions on `/var/run/docker.sock`? And have you logged out & back in since adding yorself to that group? EDIT: Glad you fixed it. You may want to answer your own question for visibility. – joelnb Apr 29 '16 at 12:06
  • @Magick, glad you solved it, but I rest my case it _was_ a duplicate issue ;) – Rick Apr 29 '16 at 12:08
  • Agh, no rest for the wicked. The error is back.... :/ – Magick Apr 29 '16 at 12:27

2 Answers2

22

Add sudo

This answer comes from Docker-Compose can't connect to Docker Daemon

TomDane
  • 1,010
  • 10
  • 25
  • 1
    For everyone who wants to avoid adding `sudo`: https://www.digitalocean.com/community/questions/how-to-fix-docker-got-permission-denied-while-trying-to-connect-to-the-docker-daemon-socket – Abhay Maniyar Jul 23 '20 at 11:29
  • @AbhayManiyar you should add an answer with those instructions. this is the correct way to do it without using sudo. – dohpaz42 Oct 28 '20 at 00:35
1

Take a look a this thread. It seems to handle the same problem.

Answer:

The Docker machine is running. But you need to export some environment to connect to the Docker machine. By default, the docker CLI client is trying to communicate to the daemon using http+unix://var/run/docker.sock (as shown in the error message).

Export the correct environment variables using eval $(docker-machine env dev) and then try again. You can also just run docker-machine env dev to see the environment variables it will export. Notice that one of them is DOCKER_HOST, just as the error message suggests you may need to set.

Community
  • 1
  • 1
Moerwald
  • 10,448
  • 9
  • 43
  • 83
  • I dont have docker-machine installed. Do I need to install machine? – Magick Apr 29 '16 at 11:16
  • 1
    Docker Machine is just a tool for managing multiple docker instances. You don't necessarily need it, but it was apparently being used in the linked thread. – Rick Apr 29 '16 at 11:22