docker / compose

Define and run multi-container applications with Docker
https://docs.docker.com/compose/
Apache License 2.0
33.89k stars 5.21k forks source link

ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running? #4181

Closed matteo-bombelli closed 7 years ago

matteo-bombelli commented 7 years ago

I know that there is another issue of the same type but the other issue is closed and I tried all the solutions proposed but with no effect.

still not working:

matteo@ubuntuDockerMB:~/wordpress-docker$ sudo docker -v
Docker version 1.12.3, build 6b644ec
matteo@ubuntuDockerMB:~/wordpress-docker$ 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.
matteo@ubuntuDockerMB:~/wordpress-docker$ sudo service docker start
start: Job is already running: docker
matteo@ubuntuDockerMB:~/wordpress-docker$ echo $DOCKER_HOST

matteo@ubuntuDockerMB:~/wordpress-docker$ DOCKER_HOST=127.0.0.1
matteo@ubuntuDockerMB:~/wordpress-docker$ echo $DOCKER_HOST
127.0.0.1
matteo@ubuntuDockerMB:~/wordpress-docker$ 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.
matteo@ubuntuDockerMB:~/wordpress-docker$ unset DOCKER_HOST
matteo@ubuntuDockerMB:~/wordpress-docker$ 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.
matteo@ubuntuDockerMB:~/wordpress-docker$ groups matteo
matteo : matteo adm cdrom sudo dip plugdev sambashare lpadmin docker

I think that I've tried all the possible configurations am I right?


Specs:


Thank You!

Aisuko commented 6 years ago

Do you have db services config like this?

      - ./db/data:/var/lib/mysql

When i input docker-compose build with db server ,I got this error. So, I input sudo chown -R $USER:$USER /db/data in order to got data permission.And I tried "docker-compose build" without the error.

docker-compose.yml

version: '3'
services:
  db:
    build:
      ./db
    command: mysqld --default-authentication-plugin=mysql_native_password
    ports:
      - "3306:3306"
    volumes:
      - ./db/data:/var/lib/mysql
    env_file:
      - mysql.env
    privileged: true
richardse08 commented 6 years ago

Restarting docker worked for me as well.

lu1s commented 6 years ago

I solved it by changing the owner from root to me to the /var/run/docker.sock. I don't know why the apt package installs as root.

$ sudo show derp:derp /var/run/docker.sock
vicmiletsky commented 6 years ago

Ran into a similar issue just now, took me a few hours to figure out the cause.

Story goes like this: we use Jenkins for CI and it runs tests for our main service with docker-compose as it relies on few other services. A coworker pushed a brach and Jenkins just failed to build it no matter what though the code and tests were perfectly fine. The problem appeared to be the following:

Solution in my case was specifying custom project name (-p) that would be used instead of default directory name:

docker-compose -f docker-compose.ci.yml -p "$SANITIZED_GIT_BRANCH" build
disarticulate commented 6 years ago

@alberto56 Fixed work:

chown -R user:user .

Also, update your .dockerignore if there's anything that's not supposed to be shipped to docker to build.

abhilash-behera commented 6 years ago

try this add sudo thats it

sudo docker-compose up
marionek111 commented 6 years ago

the solution for me is add my user to docker group, thanks that you do not must use sudo when using docker https://techoverflow.net/2017/03/01/solving-docker-permission-denied-while-trying-to-connect-to-the-docker-daemon-socket/

YokiToki commented 6 years ago

In my case if user not have permisions to /var/run/docker.sock docker-compose tryed connect to http+docker://localhost. sudo usermod -a -G docker $USER may fix that.

jomonkj commented 6 years ago

at this point https://github.com/docker/compose/issues/4181#issuecomment-317120015 restart PC will fix this problem

yummyelin commented 6 years ago

CentOS I have to say, I solved by disconnect and reconnect to the server...

lu1s commented 6 years ago

tl;dr stop unnecessary comments Guys. I think that restarting should not be part of ANY issue in GitHub. Please. It distracts us from what we are doing by non useful notifications. Keep in mind that commenting here is intended to add value to the issue itself. Restarting is not solving it because is happening again. In some point in particular the socket is stuck and so once if someone finds anything else that was not commented earlier in this thread adds value, then please do comment, then if not, please avoid creating notifications :) - sorry for the long thing.

nettree commented 6 years ago

sudo chown $USER:docker /var/run/docker.sock works for me.

Devilla commented 6 years ago

sudo which docker-compose up works fine for me on Ubuntu 16.

fedorkk commented 6 years ago

It looks like several different access problems. I've got this problem on new Fedora 28 and resolved it by disabling selinux.

Rosso84 commented 6 years ago

mine solved by typing sudo dockerd //then sudo docker-compose up -d

reneberwanger commented 6 years ago

SET a volume with "/var/run/docker.sock:/var/run/docker.sock" and will work

sriksmachi commented 6 years ago

It worked after I restarted the server :)

y2k-shubham commented 6 years ago

Mine was just because of docker-compose not being on PATH. @pelican's answer resolved it

bizzr3 commented 6 years ago

simply follow up the instruction mentioned in this issue and restart your machine.

serafdev commented 6 years ago

Just doing this worked for me:

sudo apt-get purge golang-docker-credential-helpers
mysuf commented 6 years ago

Just faced case where it worked and few rows of shell later (without any package install/upgrade), it is throwing this error. Just tried other projects and it builds so I feel something broken with docker cache or related internals to this image.. Docker image prune, restarting docker service or OS does not work. Docker is installed correctly (without need of sudoing)..

Edit: system prune and removing this particular container solved the issue

rangercyh commented 6 years ago

For me it was my user not being a member of the docker group. To solve... sudo usermod -aG docker ${USER} Then either logout & back in again, or sudo su - ${USER} to receive the updated config in your terminal

that's the correct solution

susajsnair commented 6 years ago

sudo docker-compose run ....... worked for me :)

Manacaze commented 6 years ago

I had the same problems, and fixed restarting my docker, thank you a lot

xleon90 commented 6 years ago

The answer is on Docker documentation on postinstall steps section: https://docs.docker.com/install/linux/linux-postinstall/

As reported on doc:

The Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo

This is why it works executing the command with sudo.

If you instead want your custom user to connect to docker ( as in my case ) you should add it on docker group with:

sudo usermod -aG docker $USER

In fact the ownership for the docker socket are: srw-rw---- 1 root docker 0 Oct 3 11:31 /var/run/docker.sock

After this, as reported on doc, you should log out and log back in or restart if you're testing on a virtual machine.

I've tested into an Ubuntu 14.04 virtual machine running on Parallel and I didn't need to restart it. I just needed to login again to solve the issue.

NOTE Take a look on warning indicated on documentation, cause "docker" group grants privileges equivalent to the root user. So adding an user to that group can be a security issue according to your scenario.

EdwinBetanc0urt commented 6 years ago

run the command as root

export DOCKER_HOST = 127.0.0.1

and then locate yourself in the folder of your docker-compose.yml and execute the command: su docker-compose up

rqueraud commented 6 years ago

As written in previous comments, trying to build each service individually gives more usefull error messages. I had this error because my image name was in uppercase inside the docker-compose.yml. Changing both service name and service image properties resolved the problem.

hoangquandn97 commented 6 years ago

Just restart docker and it will work perfectly. Run: service docker restart and then run any docker command that you want.

funkypenguin18 commented 6 years ago

u need to add your user to docker group to avoid "sudo docker ..." sudo usermod -aG docker username

yummyelin commented 6 years ago

Is your user in docker user group ?

sudo usermod -aG docker ${USER}

Check this article: https://medium.com/@ibrahimgunduz34/if-you-faced-an-issue-like-couldnt-connect-to-docker-daemon-at-http-docker-localunixsocket-is-27b35f17d09d

ronakganatra9 commented 5 years ago

it was not working for me also . I have just added sudo before command and it istarted working..

lattice0 commented 5 years ago

sudo dockerd

gives me

Segmentation fault

so my problem is that the docker daemon isn't running, but I don't know what I should do

croberts-indeed commented 5 years ago

I found this useful

yeszao commented 5 years ago

I upgraded my docker-compose from 1.16.1 to 1.23.1, solved it!

awalland commented 5 years ago

I am not sure what happened, I restarted my PC and it started working!!

i had the same problem and for me the reason why a restart fixed it was, that after the installation my user was added to the docker group, but this group change had only become effective through a relogin.

wyckster commented 5 years ago

I encountered this today due to a mistake I made in my docker-compose.yml file.

I accidentally included the volumes: key declaration twice, and this resulted in a failure to map docker.sock into an inner container. The mistake looked like this:

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    volumes:
      - datafiles:/datafiles

Which should just have said:

    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - datafiles:/datafiles

I discovered that when you declare two volumes sections like this, the first one is ignored. The container was, of course, not able to perform docker commands because of that.

sbarbosa115 commented 5 years ago

I had the same problem, however I was able to solve it either running the docker as a root or applying execution permissions.

I used this link https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04 on Executing the Docker Command Without Sudo section.

bobvanluijt commented 5 years ago

A slightly offtopic question, for quite some time I’m looking for documentation or references regarding the http+docker:// schema definition. Does anybody here have a URL or reference to this schema? Thanks!

sndwch commented 5 years ago

I had this problem, but realized the docker-compose error message was tremendously unhelpful and misleading. To find the actual cause I just docker build <service> manually for each service in my docker-compose.yml until I found one that refused to build. In my case, it was a permissions issue with __pycache__ in the service directory.

tauqirghani commented 5 years ago

I had the same issue and none of the solutions were helping. I tried Rosso84 idea. sudo service docker stop sudo dockerd Now I can run docker-compose up successfully. A little strangeness continues - sudo docker-compose up says command not found.

tindoantrong commented 5 years ago

it worked for me: sudo groupadd docker sudo gpasswd -a $USER docker

Either do a newgrp docker or log out/in to activate the changes to groups. newgrp docker

bramswenson commented 5 years ago

I had this issue when using an unset build arg, that was then used in the tag of my FROM image. Fix: Set the build arg to something other than a blank string.

abdulfatah66 commented 5 years ago

restarting the server solved it for me

generalomosco commented 5 years ago

If you are non-root user, then try to add the user to docker permission

sudo usermod -a -G docker theUser

fbukevin commented 5 years ago

I got it fixed by rebooting my Ubuntu as well....

M-AMAIRI commented 5 years ago

Hi ,

problem solved with sudo before the command ;) ,

Thanks, Moatez

TheMoroccan09 commented 5 years ago

It's a permission Issue.

isabirahmed commented 5 years ago

- sudo chown $USER:docker /var/run/docker.sock This worked for me in a ubuntu 18 setup.

makeplerc commented 5 years ago

I am not sure what happened, I restarted my PC and it started working!!

Take your like, sir

douglasrosa0110 commented 5 years ago

just type sudo before your docker-compose command!