Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couldn't connect to Docker daemon at http+unix://var/run/docker.sock - is it running? #1214

Closed
rept opened this issue Mar 29, 2015 · 131 comments
Closed

Comments

@rept
Copy link

rept commented Mar 29, 2015

I tried everything in this thread: #88

Still no luck.

rept@temponia:~/passenger$ netstat -ant  |grep 4243
tcp        0      0 127.0.0.1:4243          0.0.0.0:*               LISTEN     
rept@temponia:~/passenger$ echo $DOCKER_HOST
tcp://localhost:4243
rept@temponia:~/passenger$ sudo docker-compose build db uses an image, skipping
Building web...
Couldn't connect to Docker daemon at http+unix://var/run/docker.sock - is it running?

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

This is the version:

rept@temponia:~/passenger$ sudo docker version
Client version: 1.0.1
Client API version: 1.12
Go version (client): go1.2.1
Git commit (client): 990021a
Server version: 1.0.1
Server API version: 1.12
Go version (server): go1.2.1
Git commit (server): 990021a

Any ideas? I also tried installing fig which works right away without any problem...

@leoyuholo
Copy link

I get the same error message when I run docker.
It is solved by adding myself to the user group 'docker'

Try to run the following command to add yourself to the group
usermod -aG docker ${USER}

Or you can run the following command to find out what groups you belong to
groups $USER

@thaJeztah
Copy link
Member

Looks like docker-compose is disregarding the $DOCKER_HOST env var here, because it's trying to connect to the socket in stead of the 127.0.0.1 address.

@kekko1212
Copy link

same issue here

@tylerteh
Copy link

I encountered same error message just now, that time my laptop WiFi is off without wired connection. I enable WiFi and connected to home wireless network then problem solved.

@comxd
Copy link

comxd commented Aug 28, 2015

You can try the 5.0.3 (prebuild) at https://www.virtualbox.org/wiki/Testbuilds ? It's fix this issue for me.

@dagisus
Copy link

dagisus commented Sep 6, 2015

i had that problem using docker in my mac, but it got solved one i ran the compose command without sudo, so it seems it is a user issue,

@vkeziah
Copy link

vkeziah commented Sep 18, 2015

Soleved for me too with sudo command

@thaJeztah
Copy link
Member

@rept are you still having this issue? The docker version you reported is over a year old now, which is, well, pre-historic in docker terms :)

I wonder if this issue should be kept open because it's now collecting all kind of possible reasons the daemon cannot be reached (I don't mean this in a bad way; thanks everyone for suggesting solutions, it is appreciated)

@rept
Copy link
Author

rept commented Sep 18, 2015

I did a new installation on a completely different machine and it's working now. So you van close it.

@rept rept closed this as completed Sep 18, 2015
@thaJeztah
Copy link
Member

Thanks, @rept, and good to hear it was resolved!

@alexanderadam
Copy link

I get

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

too everytime I activate tty: true or stdin_open: true in docker-compose.yml and running docker-compose up.

Can it be related?

Docker version 1.9.1, build a34a1d5
docker-compose version 1.5.2, build 7240ff3

@romerobrjp
Copy link

I just solved my problem running the "docker-compose run ..." command with sudo.

@jurajseffer
Copy link

I ran into this when running docker compose up -d during vagrant up. User vagrant has been added to group docker but the above error appears when running it without sudo. It works later on if one logs in as user vagrant but fails during provisioning so it has something to do with env variables?

docker-compose version: 1.4.1

@cloojure
Copy link

Simple solution: sudo docker-compose up

@immarvin
Copy link

I ran to same issue with:

[root@c910f05c01bc07 xcat-docker]# docker-compose version
docker-compose version 1.6.2, build 4d72027
docker-py version: 1.7.2
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013

docker version:

[root@c910f05c01bc07 xcat-docker]# docker version
Client:
 Version:      1.10.2
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   c3959b1
 Built:        Mon Feb 22 16:16:33 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.10.2
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   c3959b1
 Built:        Mon Feb 22 16:16:33 2016
 OS/Arch:      linux/amd64

@mashimom
Copy link

That is a workaround not a solution, right?

@sergeyklay
Copy link

I still often face with this

@dnephin
Copy link

dnephin commented Mar 11, 2016

This is not a compose issue. If you can't connect to the docker daemon from compose there are a few likely causes:

  • you forgot to export the DOCKER_ env variables, which is often done by running eval $(docker-machine env default)
  • there is a network problem between you and the remote docker host (if you're running on a cloud provider)
  • there is a problem with the docker daemon running in the Virtualbox VM
  • your user doesn't have access to the docker daemon socket because of permissions (if you're running on a linux host). The solution is to sudo or fix the permissions.

These aren't problems that can be solved by compose.

There is an issue with tty, which is ticketed here: #3106

@madflow
Copy link

madflow commented Mar 12, 2016

I can confirm: This is not a docker-compose issue.

If it helps: I came across the same issue (Couldn't connect...) on a Ubuntu host. Running sudo systemctl status docker.service -l showed the "real" issue. The solution in my case was to remove all files in "/var/lib/docker/network/files/" and restart the docker service.

@immarvin
Copy link

hi @dnephin @madflow , I think this is a docker-compose issue.

Since with the same docker image and docker network, the container can be started up successfully with

 sudo docker run -it --privileged=true  --hostname=xcatmn --name=xcatmn --add-host="xcatmn.clusers.com xcatmn:10.5.107.101" --volume /docker/xcatdata/:/install --net=subnet1 --ip=10.5.107.101  xcat/xcat-ubuntu-x86_64

but failed with "docker-compose up". The docker-compose.yml is right the equivalent of the options and arguments of "docker run":

[root@c910f05c01bc07 xcat-docker]# docker-compose config
networks:
  default:
    external:
      name: subnet1
    external_name: subnet1
services:
  xcatmn:
    container_name: xcatmn
    extra_hosts:
      xcatmn.clusers.com xcatmn: 10.5.107.101
    hostname: xcatmn
    image: xcat/xcat-ubuntu-x86_64
    networks:
      default:
        ipv4_address: 10.5.107.101
    privileged: true
    stdin_open: true
    tty: true
    volumes:
    - /docker/xcatdata:/install:rw
version: '2.0'
volumes: {}

The docker and compose version info:

[root@c910f05c01bc07 xcat-docker]# docker version
Client:
 Version:      1.10.2
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   c3959b1
 Built:        Mon Feb 22 16:16:33 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.10.2
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   c3959b1
 Built:        Mon Feb 22 16:16:33 2016
 OS/Arch:      linux/amd64
[root@c910f05c01bc07 xcat-docker]# docker-compose version
docker-compose version 1.7.0dev, build 99d68be
docker-py version: 1.8.0-dev
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013

@dnephin
Copy link

dnephin commented Mar 14, 2016

If you can reproduce a connection issue with Compose and not with docker cli please open a new issue. Including all the information you have here is great, and also the error message, and a link to a paste with docker-compose --verbose up.

@chriskessel
Copy link

I get this if any of my container names have camel casing.

$ cat docker-compose.yml
referenceCombo:
  build: referenceCombo

$ docker-compose build
Building referenceCombo
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.

Change the name to "referencecombo" (all lowercase) and it's fine. The error message definitely doesn't help figure this one out :(

@dnephin
Copy link

dnephin commented Mar 25, 2016

@chriskessel I think your issue is covered by #2816, it's a bug in Docker Engine.

@vimalprakashts
Copy link

after restart docker services , it works for me :(

service docker restart

@Mahmoudz
Copy link

I had the same error, after 15 min of debugging. Turns out all it needs is a sudo :)
Check out [Create a Docker group] here https://docs.docker.com/engine/installation/linux/ubuntulinux/ to get rid of the sudo prefix.

@fabiopaiva
Copy link

Why needs to run with sudo?

@dpetzold
Copy link

dpetzold commented Jun 30, 2016

@fabiopaiva by default docker connects to a unix socket which is a file with root user and docker group read/write privileges:

$ ls -l /var/run/docker.sock
srw-rw---- 1 root docker 0 Jun 29 23:38 /var/run/docker.sock

so you either need to be root or a member of the docker group to connect to it. If docker was listening on a tcp socket the permissions would not apply.

@pixies
Copy link

pixies commented Jul 19, 2016

I delete file /var/run/docker.sock
how could correct?

@thaJeztah
Copy link
Member

@pixies restart the docker service should recreate it

@matchilling
Copy link

Following the steps described in the documentation resolved the issue with my new Ubuntu 16.04 installation.

I had to reboot the system after applying those changes though.

@dhirajpatra
Copy link

Use command: sudo docker-compose up -d

@derekng622
Copy link

derekng622 commented Feb 28, 2018

if u met:
$ 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.

u should check if current login user belongs to /var/run/docker.sock user group docker.
Try run Compose as sudo.

@averissimo
Copy link

averissimo commented Mar 1, 2018

To solve this without sudo do as @leoyuholo said in the second comment and logout and back in.

I get the same error message when I run docker.
It is solved by adding myself to the user group 'docker'

Try to run the following command to add yourself to the group usermod -aG docker ${USER}

Or you can run the following command to find out what groups you belong to groups $USER

After that logout and log back in and it works

link to comment #1214 (comment)

ps. this is for people like me that skip the first couple comments -_-

@abepetrillo
Copy link

Just because it takes my a long time to re-dsicover this, and is the first thing I hit on google. There is nothing wrong with my user permissions on my laptop. The problem was the file permissions on one of the mounted folders. If you either fix the permissions so you don't need root to access them, or delete them (in my case it is cached assets for rails) it successfully goes through.

The real problem is the error message does not tell you what the specific problem is when you build via docker-compose.

@zjhken
Copy link

zjhken commented Mar 10, 2018

I met the issue also. It is a user access issue.
I solved it by install docker-compose in root mode and run docker-compose also in root mode.

@t-buss
Copy link

t-buss commented Mar 10, 2018

@zjhken that is not really a solution, but rather a workaround.
There is something wrong with either the file permissions in your project folder or your group permissions. See @alexcdot and my observations for the first case, and try sudo usermod -aG docker <your username> followed by re-logging-in for the latter.

@zjhken
Copy link

zjhken commented Mar 10, 2018

@tbuss93 you're right. I have use you solution to solve it. It works. This might be the best solution.

@diptoo
Copy link

diptoo commented Mar 15, 2018

write => sudo docker info

@HargovindArora
Copy link

Just add sudo before the command which you are trying to run!

@melroy89
Copy link

melroy89 commented May 3, 2018

So in my case the gitlab_ci_multi_runner user is part of the docker group. So that is not my issue:

groups $USER
   gitlab_ci_multi_runner : gitlab_ci_multi_runner docker

But for some reason I'm still getting SOMETIMES (notice that this is sometimes the case): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Meaning I have the feeling my daemon is crashing or is instable? This is not handy, since I would like to have a stable and reliable continuous integration by using Docker. Any thoughts how I could debug this instability any further?

Thanks!

@piojoalejandro
Copy link

People, firts at all my apoligize for my english. i'm have th same problem but a realize that its happen on konsole inside kde, but when i run in a terminal crt alt f1 i dont need use sudo!. Iḿ already have $USER on docker group. I hope you ca understand me.- thanks

@alvaropaco
Copy link

Just run;

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

@aarunakirisamy
Copy link

I too faced the issue 'Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?' .Later I noticed the following.

[ec2-user@ip-172-28-6-201 docker-elk]$ which docker-compose
/usr/local/bin/docker-compose
[ec2-user@ip-172-28-6-201 docker-elk]$ which docker
/usr/bin/docker-compose

Since docker-compose binary is inside /usr/local, I was able to execute docker-compose command without 'sudo'. To execute 'docker' command, I needed sudo access.

I fixed using following commands.

cp /usr/local/bin/docker-compose /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose
sudo rm /usr/local/bin/docker-compose

Now verify 'docker-compose' command needs 'sudo' to execute.
AFter the above steps are executed, docker-compose command works for me.

@kuhajeyan
Copy link

after adding user to docker group
restarting the machine will do.

@roshangl
Copy link

For me its working.
[ec2-user@ip-172-31-7-179 docker-elk]$ sudo docker-compose up -d

My docker and docker compose version are.

[ec2-user@ip-172-31-7-179 docker-elk]$ sudo docker version
Client:
Version: 17.06.2-ce
API version: 1.30
Go version: go1.8.4
Git commit: 3dfb8343b139d6342acfd9975d7f1068b5b1c3d3
Built: Fri Nov 10 00:50:37 2017
OS/Arch: linux/amd64

Server:
Version: 17.06.2-ce
API version: 1.30 (minimum version 1.12)
Go version: go1.8.4
Git commit: 402dd4a/17.06.2-ce
Built: Fri Nov 10 00:51:08 2017
OS/Arch: linux/amd64
Experimental: false
[ec2-user@ip-172-31-7-179 docker-elk]$ sudo docker-compose version
docker-compose version 1.21.2, build a133471
docker-py version: 3.4.0
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2k-fips 26 Jan 2017

@orapradeep
Copy link

after following add user procedure make sure u restart your machine.

@mikeyjk
Copy link

mikeyjk commented Aug 3, 2018

I can reliably produce this message with a project structured like this:

├── docker-compose.yml
├── Dockerfile
└── volumes

If 'volumes' exceeds a certain size, I get the following error, when running 'docker-compose build':

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

Running the command with sudo begins to build the image, but, it's nice to not have to rely on sudo for automation.

It seems the cause of this issue in my instance is my volumes dir being passed into the build context. I guess some limitation on non-sudo users for build context size? or timeout?

So in my instance the fix is to either move the volumes dir, or add it to a .dockerignore, resolving this particular flavour of this error message.

@praveenbaliga
Copy link

cd /var/run
sudo chmod 777 docker.sock
sudo service docker start
docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.

Solved the problem :)

@bitbd83
Copy link

bitbd83 commented Aug 27, 2018

solved with sudo

@joao-pedro-alves
Copy link

If everything said here don't work, reinstall docker. It worked for me.

@jerryrelmore
Copy link

No need to restart the machine in my experience which is helpful if you're in a production environment - after sudo usermod -aG docker $USER, log out and log back in. That should pass the new user group assignment to any program or app that needs it.

Failing that, @praveenbaliga 's response 3 comments up from my comment will work in a pinch if the permissions were incorrect to begin with or you're in a staging environment, but may violate security policies if you're working in a hardened production environment. You really only want root and docker group members to have access to the docker.sock and chmod 777 will give rwx access to every user.

@bpevandro
Copy link

/usr/lib/python2.7/dist-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.23) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
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 was having the same issue just now running $ sudo docker-compose . I became root first by doing $ sudo su, and then ran the docker-compose normally.

@nileshparwan
Copy link

use this link to solve the problem as it works for me. I had the same problem but now it works fine

https://techoverflow.net/2017/03/01/solving-docker-permission-denied-while-trying-to-connect-to-the-docker-daemon-socket/

@soscler
Copy link

soscler commented Sep 25, 2018

I get the same error message when I run docker.
It is solved by adding myself to the user group 'docker'

Try to run the following command to add yourself to the group
usermod -aG docker ${USER}

Or you can run the following command to find out what groups you belong to
groups $USER

And then restart your computer

@leimao
Copy link

leimao commented Feb 8, 2019

This thread is helpful.

@zhongw117
Copy link

I entered the same issue. On the contrary, I add sudo at the beginning of my command line and it solved!

@adonese
Copy link

adonese commented Feb 17, 2019

Just run;

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

This one worked for me. Not sure why adding $USER to docker group didn't solve it.
Edit: it turns out, docker service regenerates /var/run/docker.sock every time it reloads. You need to redo the said trick every time you restart docker (won't happen too much, eh?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests