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

I tried everything in this thread: https://github.com/docker/compose/issues/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…

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 13
  • Comments: 131 (5 by maintainers)

Most upvoted comments

Soleved for me too with sudo command

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

Simple solution: sudo docker-compose up

I just solved my problem running the “docker-compose run …” command with sudo.

Just run;

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

That is a workaround not a solution, right?

after restart docker services , it works for me 😦

service docker restart

This is the correct answer. In many cases you will need to log out and log back in for the change to take effect. Running the command with sudo will work too, but adding the necessary users to the docker group is a better solution so you don’t have to give out sudo access.

leoyuholo commented on May 14, 2015

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

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,

I solved the problem adding sudo

Why needs to run with sudo?

Solution (from https://docs.docker.com/engine/installation/linux/debian/, does not only work with Debian):

Add the docker group if it doesn’t already exist. sudo groupadd docker

Add the connected user “${USER}” to the docker group. Change the user name to match your preferred user. You may have to logout and log back in again for this to take effect. sudo gpasswd -a ${USER} docker

Restart the Docker daemon. sudo service docker restart

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.

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.

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.

rebooting did the trick for me

it seams really work if restart a machine.

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

after adding user to docker group reboot is not required, just log out and login, its working for me

Use command: sudo docker-compose up -d

As mentioned above indeed:

sudo usermod -aG docker $USER

Logout. Login. Done.

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.

@CnytSntrk sorry, I solved the problem otherwise. 😉 But good luck 🍀 finding a solution!

Hi, guys I faced the same issue while I’m using Fedora 26 and then I found the solution for Fedora 25, but it does work for me.

Here is the snippet:

$ sudo groupadd docker && sudo gpasswd -a ${USER} docker && sudo systemctl restart docker
$ newgrp docker

REF: https://developer.fedoraproject.org/tools/docker/docker-installation.html

I hope it help you, Thanks

this might be another solution: sudo chmod 777 /var/run/docker.sock

sudo usermod -aG username

then Logout and login to make it work.

Worked like a charm for me.

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.29/containers/json: dial unix /var/run/docker.sock: connect: permission denied

solution: # chmod -Rf 777 /var/run/docker.sock

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

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

My problem ended up being that in my docker build context, I had files that were neither owned by my user nor my group. For example, I mounted a folder in my docker build context to a mongo container, so these files were owned by the mongodb user and group. To fix this, I just deleted that folder, and used a volume generated by docker for my mongodb service instead, and then I was able to run docker-compose without sudo

Without logout:

sudo usermod -aG docker $USER
su $USER -

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

This is because the docker daemon runs as the root user and docker-compose as a regular user

Three steps to fix it:

  1. sudo groupadd docker
  2. sudo usermod -aG docker $USER
  3. Reboot to refresh the changes.

More details in: https://docs.docker.com/engine/installation/linux/linux-postinstall/#manage-docker-as-a-non-root-user

This is still an issue on Ubuntu 16.04 and adding myself to the docker group, then relogging worked. This issue should not be closed.

sudo systemctl status docker.service -l is very useful to find the real problem.

I had the same but only with docker-compose build. This was finally just a problem of file permission. I created files inside the container, owned by root, and it was not able to build with those files. I simply did a sudo chown -R $USER . and it works.

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. The docker daemon always runs as the root user. Linux Post Install

$ sudo groupadd docker
$ sudo usermod -aG docker $USER

reminder: (remember to restart session or reboot VM )

  • If testing on a virtual machine, it may be necessary to restart the virtual machine for changes to take affect.
  • On a desktop Linux environment such as X Windows, log out of your session completely and then log back in.

I had this problem on a code repo that was building fine one moment and then not. I had other repos on the same machine and same account that built just fine, so it wasn’t a groups issue or anything with the system configuration. I had no DOCKER_HOST env var set. I suspect this error can be caused by a variety of reasons, but for me it ended up being root ownership of the build artifacts in the repo directory. sudo chown -R all files in the repo to the user account solved the problem for me.

on Fedora Linux add your user to docker group sudo usermod -aG docker username

after this command reboot, logout is not enough as on other distros

usermod -aG docker ${USER} then reboot.

If you installed docker using sudo command, try sudo YOUR_COMMAND.

@Farada changing the permissions is dangerous; having access to the Docker API is equivalent to having root access on your machine; changing the permissions to 777 gives anyone on the host root access.

Nothing is better than recommending the official doc:

https://docs.docker.com/engine/installation/linux/linux-postinstall/

check this out.

The official doc is always the first place where you should go for help.

Does anyone knows how to run it without using sudo?

I just solved my problem running the “docker-compose run …” command with sudo.

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.

I still often face with this

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?)

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

I had the same problem. As others have mentioned, when I ran the docker-compose with sudo, it worked.

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 😃

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

I can confirm @alexcdot observation: Had files in my project repository owned by root (dunno how they got there). Deleting them resolved the issue. Now I can run docker-compose without sudo privileges.

Instead of rebooting you can just type su - ${USER}. I guess this reloads the currently active user in the Terminal.

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04

I’ve been getting this:

 docker-compose build
db uses an image, skipping
Building web
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.

The issue was that some files in the context of the Dockerfile had restrictive permissions, a quick sudo chown -R damo ./* fixed it.

However I would argue there is indeed an issue with docker-compose here — I should have received an informative error message that accurately specifies that it failed because of a permissions error, rather than an ambiguous connection error which was a red herring in my case as I wasted time messing with the docker daemon service itself.

I had the same problem and in my case the cause was that I had some files in the folder with Dokcerfile to which I had no access rights. After running chown all started to work nice. The solution with usermod hasn’t been working for me.

UPDATE It has happened again for me and this time the solution was to remove all docker containers with:

docker ps -aq | xargs docker rm

So I ended up adding the user to the docker group:

sudo groupadd docker
sudo usermod -aG docker $USER
sudo service docker restart

I still had connection issues when running docker ps as the user giving me the following error:

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.27/containers/json: dial unix /var/run/docker.sock: connect: permission denied

Rebooting the server fixed this issue allowing me to run docker commands as the user without using sudo:

sudo reboot now
... (wait for boot) ...
ssh server
docker ps

EDIT:

It was mentioned that you just need to logout/login for this to update, no restart needed to run docker commands without sudo after adding the user to the docker group.

I had to also start the docker service manually after a new installation of docker-ce (17.12.0~ce-0~ubuntu) and docker-compose to make the error message disappear:

sudo service docker start

Also confirming the @alexcdot and @tbuss93 solution. Worked for me as well. I think that in such case, the error should be more user-friendly and ideally show problematic files.

Restarting solved after doing

sudo usermod -aG docker ${USER}

@mordonez-me, adding into docker group will help.

sudo gpasswd -a ${USER} docker

In general, I have following installation steps in Centos 7 with root user:

# Remove SELinux for dev VMs
yum remove -y selinux*
# Docker
curl -fsSL https://get.docker.com/ | sh
systemctl enable docker
systemctl restart docker
curl -L https://github.com/docker/compose/releases/download/1.8.1/docker-compose-`uname -s`-`uname -m` \
  > /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose
gpasswd -a vagrant docker

And after that it works fine with my non-root vagrant user.

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 😦

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

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 https://github.com/docker/compose/issues/1214#issuecomment-102246925

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

This solved my problems: https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user Just remember to log out and log back in. Run the commands as the user you want to use docker.

i had this issue today for a new Dev notebook. I solved it like this

  1. Stop Docker
sudo service docker stop

if you look at this file permission you’ll see that without sudo you won’t be able to get access to Docker daemon

sudo ls -la /var/run/docker.sock
srw-rw---- 1 root docker 0 Dec 21 19:16 /var/run/docker.sock
  1. I remove this docker.sock
sudo rm  /var/run/docker.sock

thanks @rbahumi 3) i run this command

sudo usermod -aG docker ${USER}

and now you are almost done just Log out or better just restart the computer you don’t have to start the service because it start automatically

This worked for me without the reboot:

  1. Add docker group: sudo usermod -aG docker ${USER}
  2. Run id
  3. If the ‘docker’ group does not appear in the group list - logout and login again

I personally tried @cloojure 's solution and it worked. But only after I added myself to docker group and re-login. The re-login part is essentail

FWIW, I needed a system restart before it started working for me. This was likely due to the fact the linux-image-extra-* kernel packages were freshly installed as required by docker on Ubuntu Xenial. See Prerequisites by Ubuntu Version.

this only worked for me after logging in and out after adding my user to the docker group.

@mikevoets yes I think that should solve this issue.

I had the same thing happen on a new install and realized it was because I wasn’t using ‘sudo’.

Ubuntu 16.04 has the same error

@pixies restart the docker service should recreate it

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