Docker-Compose can't connect to Docker Daemon

UbuntuTerminalDockerDocker Compose

Ubuntu Problem Overview


I am getting an error message saying I can't connect to the docker daemon. I have looked into other people's answers who have had similar issues but it hasn't helped. I am running the version of Ubuntu 15.10. I will try to provide all the info I have.

root@# docker-compose -f docker-compose-deps.yml up -d
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.

Docker Version

root@# sudo docker     version
Client:
Version:      1.9.1
API version:  1.21
Go version:   go1.4.2
Git commit:   a34a1d5
Built:        Fri Nov 20 13:20:08 UTC 2015
OS/Arch:      linux/amd64
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

Docker-Compose Version

root@# docker-compose --version
docker-compose version 1.5.2, build 7240ff3

This is what happens if I try to stop or start the service...

root@# sudo service docker stop
stop: Unknown instance: 
root@# sudo service   docker start
docker start/running, process 5375

If I run ps aux | grep docker

root@# ps aux | grep docker
root      4233  0.0  0.0  13692  2204 pts/15   S+   10:27   0:00 grep --color=auto docker

Any help would be greatly appreciated. Let me know if you may need anymore information.

Ubuntu Solutions


Solution 1 - Ubuntu

I had the same error, after 15 min of debugging. Turns out all it needs is a sudo :)

Check out Manage Docker as a non-root user to get rid of the sudo prefix.

Solution 2 - Ubuntu

I had this problem and did not want to mess things up using sudo. When investigating, I tried to get some info :

docker info

Surprinsingly, I had the following error :

> Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http:///var/run/docker.sock/v1.38/info: dial unix /var/run/docker.sock: connect: permission denied

For some reason I did not have enough privileges, the following command solved my problem :

sudo chown $USER /var/run/docker.sock

Et voilà !

Solution 3 - Ubuntu

It appears your issue was created by an old Docker bug, where the socket file was not recreated after Docker crashed. If this is the issue, then renaming the socket file should allow it to be re-created:

$ sudo service docker stop
$ sudo mv /var/lib/docker /var/lib/docker.bak
$ sudo service docker start

Since this bug is fixed, most people getting the error Couldn't connect to Docker daemon are probably getting it because they are not in the docker group and don't have permissions to read that file. Running with sudo docker ... will fix that, but isn't a great solution.

Docker can be run as a non-root user (without sudo) that has the proper group permissions. The Linux post-install docs has the details. The short version:

$ sudo groupadd docker
$ sudo usermod -aG docker $USER
# Log out and log back in again to apply the groups
$ groups  # docker should be in the list of groups for your user
$ docker run hello-world  # Works without sudo

This allows users in the docker group to run docker and docker-compose commands without sudo. Docker itself runs a root, allowing some attacks, so you still need to be careful with what containers you run. See Docker Security Documentation for more details.

Solution 4 - Ubuntu

I had the same issue. After taking notes and analyzing some debugging results, finally, I solved what can be the same error. Start the service first,

service docker start

Don't forget to include your user to the docker group.

Solution 5 - Ubuntu

just try with sudo. It seems like permission issue!

sudo docker-compose -f docker-compose-deps.yml up -d

it worked for me.

Solution 6 - Ubuntu

One way to resolve this would be to first add your user to the docker group by running the following

sudo usermod -aG docker $USER

IMPORTANT: Remember to log out of your system (not just your terminal) and back in for this to take effect!

Solution 7 - Ubuntu

You should adding your user to the "docker" group with something like:

> sudo usermod -aG docker ${USER}

Solution 8 - Ubuntu

in my case it is because the ubuntu permission,

  1. List item

check permission by

docker info 

if they print problem permission, enter image description here then use

sudo chmod -R 777 /var/run/docker.sock

Solution 9 - Ubuntu

I got this error when there were files in the Dockerfile directory that were not accessible by the current user. docker could thus not upload the full context to the daemon and brought the "Couldn't connect to Docker daemon at http+docker://localunixsocket" message.

Solution 10 - Ubuntu

From the output of "ps aux | grep docker", it looks like docker daemon is not running. Try using below methods to see what is wrong and why docker is not starting

  1. Check the docker logs

$ sudo tail -f /var/log/upstart/docker.log

  1. Try starting docker in debug mode

$ sudo docker -d -D

Solution 11 - Ubuntu

Another reason why this error can show up: for me it was a malformed image-path definition in the docker-compose.yml:

  service:
    image: ${CONTAINER_REGISTRY_BASE}/my-service
   ...

Lookis ok'ish first, but i had CONTAINER_REGISTRY_BASE=eu.gcr.io/my-project/ set on the env. Apparently the // in the image path caused this error.

docker-compose: v.1.21.2
docker: 18.03.1-ce

Solution 12 - Ubuntu

In my case your docker service might be stopped

Command to start docker service:

$ sudo systemctl start docker

Command to verify if it start:

$ sudo docker run hello-world

Solution 13 - Ubuntu

I used Ubuntu 16.04 and found this problem too when I used docker-compose. I fixed it by running this command.

$ sudo systemctl start docker
$ sudo docker-compose build

Solution 14 - Ubuntu

Is there slight possibility you deleted default machine? But, first check if all files are there (OSX, similar on other systems)

brew install docker docker-compose docker-machine xhyve docker-machine-driver-xhyve
brew link docker docker-compose docker-machine xhyve docker-machine-driver-xhyve

sudo chown root:wheel /usr/local/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve
sudo chmod u+s /usr/local/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve

Also, install Docker App, as it much easier to maintain containers:

brew cask reinstall docker

ans start Docker app from finder (wait until service is fully started)

Then, check instalation with:

docker-machine ls

if no machines are present in list, create one and start it:

docker-machine create default
docker-machine start default

After this, build, compose and all other commands should work properly.

Solution 15 - Ubuntu

In my case a have the same error when I try to docker-compose build and my solution was just add sudo

sudo docker-compose build

Solution 16 - Ubuntu

For me the fix was to install a newer version (1.24) of docker-compose using this article.

The previous version (1.17) was installed from ubuntu's default repository, but after installing a newer version I managed to launch the container. Hope it helps somebody.

Solution 17 - Ubuntu

I think it's because of right of access, you just have to write

sudo docker-compose-deps.yml up

Solution 18 - Ubuntu

In my case problem was with the inappropriate image tag name -backend - started with a short leading dash:

FAILED:

version: '2.4'

services:
  my-service:
    container_name: my.backend
    image: imagename:-backend
    build:
      context: .
    

Error message:

ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.

WORKS: with my-backend

version: '2.4'

services:
  my-service:
    container_name: my.backend
    image: imagename:my-backend
    build:
      context: .
    

Solution 19 - Ubuntu

It helped me to sudo chown -Rv someuser.someuser ~someuser/docker_compose_dir/, where someuser is the user I run docker-compose under. After that, docker-compose went smoothly.

Solution 20 - Ubuntu

YOU NEED A POST DOCKER INSTALLATION GROUP CONFIGURATION FOR PERMISSION


sudo usermod -aG docker ${USER}
su - ${USER}
id -nG
sudo usermod -aG docker username

RUN THE ABOVE COMMANDS ON YOUR TERMINAL ONE-BY-ONE, if you really wanna know what each step means check (STEP 2) out HERE

Then try connecting again

Solution 21 - Ubuntu

Final Solution: First run this command: sudo chown $USER /var/run/docker.sock Then run this command: docker-compose up -d --build

Solution 22 - Ubuntu

I found this and it seemed to fix my issue.

GitHub Fix Docker Daemon Crash

I changed the content of my docker-compose-deps.yml file as seen in the link. Then I ran docker-compose -f docker-compose-deps.yml up -d. Then I changed it back and it worked for some reason. I didn't have to continue the steps in the link I provided, but the first two steps fixed the issue for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondaveskylarkView Question on Stackoverflow
Solution 1 - UbuntuMahmoud ZaltView Answer on Stackoverflow
Solution 2 - UbuntumadjaoueView Answer on Stackoverflow
Solution 3 - UbuntujwhitlockView Answer on Stackoverflow
Solution 4 - UbuntuR AView Answer on Stackoverflow
Solution 5 - UbuntuDemobilizerView Answer on Stackoverflow
Solution 6 - UbuntuarunavkonwarView Answer on Stackoverflow
Solution 7 - UbuntuzhiikerView Answer on Stackoverflow
Solution 8 - Ubuntujoe-khoaView Answer on Stackoverflow
Solution 9 - UbuntucweiskeView Answer on Stackoverflow
Solution 10 - UbuntuManish RView Answer on Stackoverflow
Solution 11 - UbuntuleberknechtView Answer on Stackoverflow
Solution 12 - UbuntuJohn_JView Answer on Stackoverflow
Solution 13 - UbuntuKhachornchit SongsaenView Answer on Stackoverflow
Solution 14 - UbunturapttorView Answer on Stackoverflow
Solution 15 - UbuntuAndrey TopoleovView Answer on Stackoverflow
Solution 16 - UbuntuArtyom IlyinView Answer on Stackoverflow
Solution 17 - UbuntuMoustapha BerrouView Answer on Stackoverflow
Solution 18 - UbuntuVolodya LombrozoView Answer on Stackoverflow
Solution 19 - UbuntuEugene Gr. PhilippovView Answer on Stackoverflow
Solution 20 - UbuntuvictorkolisView Answer on Stackoverflow
Solution 21 - UbuntuAshraf GardizyView Answer on Stackoverflow
Solution 22 - UbuntudaveskylarkView Answer on Stackoverflow