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

Created on 24 Nov 2016  ·  204Comments  ·  Source: docker/compose

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'm part of the docker group

  • I'm using also sudo

  • The process is up

  • The DOCKER_HOST variable is unset or 127.0.0.1

  • Reconnected the user

  • Restarted the server

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


Specs:

  • OS: Ubuntu 14.04.04 on Virtualbox on Windows 10 Home.

  • Docker version 1.12.3, build 6b644ec


Thank You!

kinquestion

Most helpful comment

Have you tried without sudo? You shouldn't need it and it could be messing things up in your case. Also, what do you see when you run docker info?

All 204 comments

Have you tried without sudo? You shouldn't need it and it could be messing things up in your case. Also, what do you see when you run docker info?

Try running dockerd or sudo dockerd if required first to start daemon. If you start dockerd with sudo you may want to run docker-compose up with sudo also. otherwise it's fine.

@shin- Hello! I've already done it with with sudo and also using root (sudo su).

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.

here is the operation made as root

root@ubuntuDockerMB:/home/matteo/wordpress-docker# 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.
root@ubuntuDockerMB:/home/matteo/wordpress-docker#

this is the result of docker info

root@ubuntuDockerMB:/home/matteo/wordpress-docker# docker info
An error occurred trying to connect: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.24/info: read unix @->/var/run/docker.sock: read: connection reset by peer

@harshajayaweeraXHJ

dockerd does not work but sudo service docker start works as expected

matteo@ubuntuDockerMB:~/wordpress-docker$ sudo dockerd
INFO[0000] libcontainerd: new containerd process, pid: 4039
WARN[0000] containerd: low RLIMIT_NOFILE changing to max  current=1024 max=4096
INFO[0001] [graphdriver] using prior storage driver "aufs"
FATA[0001] Error starting daemon: layer does not exist

PS:

@shin- & @harshajayaweeraXHJ Sorry for being late

You need to export the variable for it to be available in child processes:

$ export DOCKER_HOST=127.0.0.1

Although this doesn't completely solve your issue...

I ran into this error because I foolishly ignored the ubuntu prerequisites.

thank you @jamethy, I,ve done just right that and i get

matteo@ubuntuDockerMB:~/wordpress-docker-tut$ docker-compose up -d
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "compose/cli/main.py", line 65, in main
  File "compose/cli/main.py", line 114, in perform_command
  File "compose/cli/command.py", line 36, in project_from_options
  File "compose/cli/command.py", line 111, in get_project
  File "compose/cli/command.py", line 83, in get_client
  File "compose/cli/docker_client.py", line 74, in docker_client
  File "site-packages/docker/client.py", line 59, in __init__
  File "site-packages/docker/utils/utils.py", line 438, in parse_host
docker.errors.DockerException: Bind address needs a port: 127.0.0.1
docker-compose returned -1

Having the same problem now, also trying to install Wordpress under docker. Tried everything, but still can' t connect. Docker daemon is not running... I'll try it again

for me the problem stays there:

Bind address needs a port: 127.0.0.1

but this number should be created by docker itself

I have the same problem as the original poster, and have tried all the suggested things above.

It seems that sometimes docker "dies" and is not running, and at other times it stays running. I noticed this while trying to run the docker info command and getting an error about docker not running. Using service docker start then allowed me to run the info command. This is what I got:

Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 1.12.5
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 3
Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: host bridge overlay null
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: apparmor seccomp
Kernel Version: 4.4.0-45-generic
Operating System: Ubuntu 16.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 24
Total Memory: 31.42 GiB
Name: ayn
ID: 7TGC:G5WQ:6IYF:XWMH:XF3N:VXU7:SLZB:IHRN:T4FL:D35I:5JUA:H4S5
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Insecure Registries:
127.0.0.0/8

@matteo-bombelli This error is pretty clear, you need to specify a port. Do export DOCKER_HOST=127.0.0.1:2375 instead.

@matteo-bombelli
I had the same issue.
You need to restart docker.
$ service docker restart
I solved it with this.

can anyone consolidate the solution for this problem in steps ?

Hi. I second this last comment, I am having the same issue.

I am having the same issue.

docker ps works.

docker-compose build (with version 2) works!

docker-compose build (with version 3) gives this error :/

@furkanmustafa @shashijais789 @lalitkumarj It'd be better if you created a new issue with all the info. There are many reasons that can cause a failure to connect to the engine, from network to configuration to the engine potentially crashing / being stopped. Please also make sure to include the engine logs with the debug -D flag.

same problem. works with version 2, I get this error with verison 3 config.

the following steps solved the problem for me.

remove docker:
$ sudo apt-get remove docker docker-engine
reinstall with
curl -sSL https://get.docker.com/ | sh

add user to a group:
sudo usermod -aG docker user

Maybe this error can be displayed if one of the images fails to build for whatever reason, not necessarily having to do with the docker daemon. For example, I have managed to debug this by trying to build each service using Docker.

My docker-compose.yml file contains:

version: '2'

services:
  # Drupal server
  drupal:
    build:
      context: .
      dockerfile: "Dockerfile-drupal"
  mysql:
    ...

Calling docker-compose build results in:

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

So I tried to use Docker to build each file individually:

docker build -f="Dockerfile-drupal" .

This gave me a more useful error:

Error checking context: 'no permission to read from some/data/directory'

Fixing that error and making sure I can build Dockerfile-drupal resulted in docker-compose build working fine.

Perhaps the code which outputs the error might be changed to something like:

Couldn't build the services.

 * Make sure you can build your Docker images using "docker build ...".
 * Make sure the Docker daemon is running.
 * If the Docker daemon is at a non-standard location, specify the URL with the DOCKER_HOST environment variable. Currently using http+docker://localunixsocket.

Needed all of:
1) apt-get remove and re-install using curl as Kirill-Babkin suggests (and restart socker to be safe)
2) add user to docker group using usermod -aG, logout and login
3) undefine DOCKER_HOST (as suggested by rkazak at https://forums.docker.com/t/docker-commands-require-sudo/12987/2) which I had earlier set using >export DOCKER_HOST=127.0.0.1:2375 as suggested by jamethy and shin
This was on an RPi 3B. After all of this, docker is now working. Is there any chance this could be cleaned up so others don't have to go through this painful experience, as it is experiences like this docker is designed to fix? Just a suggestion.

In my case LAN proxy (that is defined in Internet Options - I am on Windows) had prevented docker-compose from connecting to VM (with docker engine) on VirtualBox Host-Only Network - disabling proxy has solved an issue.

On Ubuntu 16.04 this worked for me:
sudo service docker start && docker-compose up -d

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

@ssi-anik that's computer science 😄

I just had the same issue. I found that for some reason my user was not added to the docker security group, in turn not allowing me permission on docker's unix socket and giving me _ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running_.

Adding the docker group to my current user, then logging out and back in again fixed everything for me:
sudo usermod -aG docker $USER

This was failing at a certain build step for me, I tried running docker build . in the same directory as the Dockerfile and found that one of the files that I was trying to COPY had permission issues.

Running sudo chmod 755 -R . fixed my issue.

As mentioned by @ChrisPappalardo at
https://github.com/docker/compose/issues/1214
check for file ownership permissions within your build directories. As the container build process is done in the context of the current user, having a inaccessible directory within the tree owned by root can lead to an error resulting in this message.

In my case @alberto56's solution worked perfectly it was a permissions issue with one of the volumes that was mounted to one of my services. Not sure how the ownership got changed in the first place but doing the manual docker build -f myDockerfile . helped me find my issue.

When I did an ls -l the directory was owned by 999 and docker group, the weird part is that it wasn't even for the image I was trying to build, it was a separate service.

I ran into this error because I mounted a volume like so, while debugging, and forgot to clean up.
volumes:
- ./itsLog:/var/log/itsLog

when I tried to build the Dockerfile, it must have received a "permission denied" while trying to ADD the restricted path.

The description of the error is some-what misleading, but otherwise it makes sense.

I just changed the file /var/run/docker.sock owner to current user, and it's ok.
It seems that docker-compose had no permission to access /var/run/docker.sock.

The description of the error is some-what misleading

Since it already is so uninformative, why not really commit to it and just print "No."? /s

In my case I had to review syslog to see that Docker daemon rejected build specification because there were capital letters in tag string.

This error message is a blanket statement and probably should be documented (instead of scattered across Stack Overflow and github issues of unrelated projects) or expanded upon.

@alberto56 's comment helped me. Had the same issue. Thanks!
Previous container that I had "volumed" had created compiled Python files; *.pyc. Those were not accessable to my user.
Problem and fix copied from above:

Calling docker-compose build results in:
Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?

Call docker directly:
docker build .

Which reveals the real cause:
Error checking context: 'no permission to read from '/home/user/dev/project/app/utils.pyc''.

File permissions were:
-rw-r----- 1 root root 11K Nov 29 16:32 utils.pyc
And fix was to delete those files:
sudo rm app/*.pyc

Hey Guys,

After upgrading to docker version 17.12 and I have started the docker service it resolved my issue.

[]# service docker start
13 Redirecting to /bin/systemctl start docker.service
# sudo docker-compose up -d

We need to update the docker version and then compose will work.

Regards,
Prasad RVS

service docker start
Redirecting to /bin/systemctl start docker.service
[root@kammu02-I9084 LDDS]# sudo docker-compose up -d
Creating network "ldds_default" with the default driver
Creating volume "ldds_couch-data" with default driver
Pulling couchdb (isl-dsdc.ca.com:5000/analytics/lddscouchdb:2.1.8c.109)...
2.1.8c.109: Pulling from analytics/lddscouchdb
dd6405a9d644: Pull complete
10f659fc3a7e: Pull complete
8a0ce719aeb8: Pull complete
fc23f8fbeac2: Pull complete
5f02dd664e80: Pull complete
f38b89a75914: Pull complete
94add1a2ec1e: Pull complete
e7db1a0942ee: Pull complete
87b0136db4b9: Pull complete
be9ceeef7cb5: Pull complete
aed07b38ec55: Pull complete
fc4632d89301: Pull complete
6152a07afebb: Pull complete
946862fd0151: Pull complete
43408ca5f730: Pull complete
Digest: sha256:d3c13f08a4c9c3ed450325aef2dbe97abf0a55c13e9e2005109c05c713491fb3
Status: Downloaded newer image for isl-dsdc.ca.com:5000/analytics/lddscouchdb:2.1.8c.109
Pulling ldds-web (isl-dsdc.ca.com:5000/analytics/lddscdb:2.1.8c.109)...
2.1.8c.109: Pulling from analytics/lddscdb
dd6405a9d644: Already exists
10f659fc3a7e: Already exists
8a0ce719aeb8: Already exists
eebc892936a1: Pull complete
3c8dd6086ddb: Pull complete
73c1dfebea61: Pull complete
9fb23fd0d390: Pull complete
f8943ba49c47: Pull complete
a89ff5b6e340: Pull complete
02615a9d0e05: Pull complete
e129088bf324: Pull complete
bf0ba8d71b09: Pull complete
083300d85e61: Pull complete
5deacfd6cb23: Pull complete
220cda5539ae: Pull complete
8cdee22c663b: Pull complete
d76b24524469: Pull complete
9c5ade36643f: Pull complete
c7ca782f404c: Pull complete
6a7bbcfb0b95: Pull complete
Digest: sha256:e2cb43e6b22ab344d7fc17f38e49caa3e295ef0efdfa43bc77ce671e0f172168
Creating ldds_couchdb_1 ... done
Creating ldds_couchdb_1 ...
Creating ldds_ldds-web_1 ... done

I did encounter the below error,
" couldn't connect to Docker daemon at http+docker://localunixsocket - is it running? "

Check if it is permission issue, execute "sudo docker ps" executes without this error and "docker ps" executes with this error, then permission issue.

Try this docker post install steps. You may need to add the "user" to the docker group.
https://docs.docker.com/engine/installation/linux/linux-postinstall/

This worked for me.

Hi all - this happens on my machine as well. What's weird is that I've made no changes or upgrades what-so-ever and it just started happening.

@manjukori this happens to me even though I'm in the docker group - yet running the same command under sudo works! So on one hand, it seems you're correct that it's some sort of a permissions issue, yet, I am a member of the docker group! So weird...

Ok everyone found the issue! In my case, I'm using docker-compose that mounts a root-owned directory into one of the containers. For some reason that prevented docker-compose (which runs docker build) from booting.

As soon as I removed this directory, everything works as before (though I'm not sure why it worked before actually).

You might want to check for something similar on your end as well.

chmod 777 it

Your user needs to be in the "docker" group to run docker-compose without sudo. Just add this group to your account, log out and log back in. Fixed this for me on Ubuntu and Mac OS.

@jhnoor thanks! It worked for me
sudo chmod 755 -R .

I would like to reiterate one of the most useful comments on the other issue which said that docker-compose --verbose up[|build] will help you get to the bottom of your issue. In my case, docker-compose's error message was misleading--I just needed to update from docker 1.10 (ancient) to 1.12.

Verbosity revealed this:
docker.errors.APIError: 400 Client Error: Bad Request ("client is newer than server (client API version: 1.24, server API version: 1.22)")

In my case, only single command was enough to fix the issue: sudo usermod -aG docker $USER (when $USER is your current logged in user). With this I've got successful run of docker-compose run ... without sudo from $USER user shell. (Thanks, @Kirill-Babkin :cake:).

  • Ubuntu 16.04.3 (super clean new instance on AWS)
  • Docker 17.12.1-ce (installed over apt, followed Get Docker CE for Ubuntu)

The correct answers are from @manjukori and @yoloseem; only thing I would emphasize is to use the env variable $USER to generalize the instruction sudo usermod -aG docker $USER (assuming you are connected to the shell as the user that needs to manage docker). For other important details around docker config, see the link as posted above https://docs.docker.com/install/linux/linux-postinstall/.

@ramblinwreck35 Edited my comment as you pointed. :+1:

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

systemctl restart docker
resolve it

This is due to permission even after adding the your user in docker group. restart group or reload permission.

I used sudo. problem solved.

I'm not entirely sure if my problem was the same, but I post my solution here in case somebody else has the same problem and comes across this thread.

In my case, I forgot to add some directories to the .dockerignore. I guess it was too much data for the docker deamon, because it worked after excluding some data directories.

@harwood and I were investigating this issue in our repository and saw that is actually due to a malformed docker image name that is set in image - we had an image with a capital letter. We were also supplying build: ./. When we removed build: ./ We saw a new error message: invalid reference format: repository name must be lowercase. Hope this helps anyone tracking this issue.

Hi,

My problem was solved with the following steps:

  1. Stop the docker service
  2. Add the user you are using to run the docker-compose command to the docker group with the following command: usermod -aG docker NAME_OF_USER (CentOS 7)
  3. Start the docker service

Do you have db services config like this?

```volumes:
- ./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
```

Restarting docker worked for me as well.

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

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:

  • Jenkins creates a folder for each pipeline and shortens its name to some length. It makes up a folder name like "$GIT_BRANCH-$RANDOMISH_HASH" and curious part is that it truncates string from the beginning.
  • The failing branch name contained dashes (-), and the resulting directory name generated by Jenkins ended up starting with -.
  • Then Jenkins would run docker-compose in that folder, and by default docker-compose uses directory name as a prefix to name containers.
  • This means that it tries to create containers with names that start with dash (-) and that appears to be an illegal character for a docker container's name to start with.
  • And then docker-compose fails with a generic error with a misleading "Couldn't connect to Docker daemon - is it running?" message.

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

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

try this add sudo thats it

sudo docker-compose up

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/

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.

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

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

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.

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

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

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

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

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

It worked after I restarted the server :)

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

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

Just doing this worked for me:

sudo apt-get purge golang-docker-credential-helpers

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

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

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

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

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.

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

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.

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

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

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

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

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

I found this useful

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

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.

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.

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.

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!

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.

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.

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

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.

restarting the server solved it for me

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

sudo usermod -a -G docker theUser

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

Hi ,

problem solved with sudo before the command ;) ,

Thanks,
Moatez

It's a permission Issue.

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

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

Take your like, sir

just type sudo before your docker-compose command!

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

usermod -a -G docker USER
Then logout and login again USER.

I encountered the same error whenever I had a variable inside docker-compose.yml that is NOT present within .env.

Weird error for such scenario but - whatever. :)

just type sudo before your docker-compose command!

Take your like, sir!
omg..., but works fine for me, great job!

i just had to do:
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

and it worked!

Yo instalé docker-compose y la vez resolvíe el problema con los siguientes pasos:
paso 1:
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-uname -s-uname -m -o /usr/local/bin/docker-compose

paso 2:
sudo chmod +x /usr/local/bin/docker-compose

paso 3:
docker-compose --version

paso 4:
export DOCKER_HOST=127.0.0.1:2375

paso 5:
usermod -a -G docker $USER

paso 6:
Reiniciar tu pc o ejecutar el comando
shutdown

This worked for me:

sudo usermod -aG docker $(whoami)

logout

login

check to be sure you are in the "docker" group.

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

thx!

Hello,
got same error message:

ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

But this message was misleading, because my docker deamon does not had any problems in connections.
The reason was a stupid mistake I made in the Yaml (which I didn't know before). I accidentally had a capital letter in the image name. That led to the fact that the service could not be formed, since only lower case letters are permitted as names.
I noticed the error when I tried to build the Dockerfile separately with the names.
It would be handy if docker-compose could forward the errors that occur within build problems. Since, as @shin- also said, this bug can still occur for many reasons at this time. Even though it's been some time since @shin- wrote this, the problem still seems to exist. Maybe it might be helpful.

Just posting my issue here, cause everyone is strictly thinking on real connection problems with docker and i wanted to show, that it does not need to be always the case.

$ cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core) 

$ sudo service docker start
$ sudo service docker status

Hello,

I faced the same issue. But it got resolved after I restarted my VM.

BR.Saurabh

that command solves to me:

sudo usermod -aG docker user

commands:

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
sudo docker-compose up -d

If you just installed docker and just granted a user the docker group try logging out of that user and logging back in again.

sudo service docker start && docker-compose up -d

Please try with above command. Issue is fixed for me

None of the listed above solutions have fixed it for me. Any other ideas?

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

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

resolvi o problema com esse comando:

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

👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻
👉🏽SOLUTION 👈
👆🏿👆🏿👆🏿👆🏿👆🏿👆🏿

if you haven't tried anything yet from this tread run these two commands and it will solve this particular problem:
sudo usermod -a -G docker $USER # adds your current user to docker group
newgrp docker # activates new permissions for docker group

sudo usermod -a -G docker $USER # adds your current user to docker group
newgrp docker # activates new permissions for docker group

Should be newgrp -l docker. When using this people should be aware that newgrp starts a new shell so their environment will be reset as if they logged in freshly again if they use -l.

First we need to remount tmp with exec permission by executing

  1. sudo mount /tmp -o remount,exec
    then make docker up by
  2. "service docker start" in root user or "sudo service docker start"
    then
  3. "docker-compose up" or "docker-compose start" worked for me

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

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
加上sudo也是报同样的错误

groups root
root : root docker
root在docker组下

Resolved the issue with this:

  1. sudo usermod -aG docker $USER
  2. Log out and log back in so that your group membership is re-evaluated.
  3. Verify that you can run docker commands without sudo: docker info

The default DOCKER_HOST is unix:///var/run/docker.sock . If this file doesn't exist or your current user doesn't have access to that file then its trying to connect to http+docker://localhost
Try:
sudo chown /var/run/docker.sock
Then again try to run docker-compose up
Worked for me.

Have you tried without sudo? You shouldn't need it and it could be messing things up in your case. Also, what do you see when you run docker info?
Thanks! it works!

But please Docker, add a correct warning!

i got this message when copying volumes from poruction machine, ended up to owerdrite metadata.db inside /var/lib/docker/volumes, then it crashes. A fix is so smiple

docker system prune --volumes -f && rm /var/lib/docker/volumes/metadata.db && docker-compose up -d

This often happens when you run docker commands as sudo whiles you run docker-compose commands without it.
What you need to do is to add docker user to the sudo group. (ie. usermod -aG docker $USER)
Then you can run both comands (docker and docker-compose) without sudo.

I had exactly the same error. I removed the container (id) and started the docker again. That fixed the problem for me. It doesn't delete any data which was already uploaded.

Go into your cvat directory and run the following in your terminal:

  • sudo docker ps (shows information about your running dockers)
  • docker stop "Here the ID of your container" (e.g. mine was e6339eae0675)
  • sudo docker rm "Here the ID of your container"
  • sudo docker-compose up -d

i have the same problem, _sudo docker-compose up_ work for me.

The solution for me was to stop my openvpn that I was using.

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

This works.

the following steps solved the problem for me.

remove docker:
$ sudo apt-get remove docker docker-engine
reinstall with
curl -sSL https://get.docker.com/ | sh

add user to a group:
sudo usermod -aG docker user

Just a note that you need to exit the shell and login again for the usermod command to stick.

I just suffered again same issue as before, and found sime light at the end...
It it is related to that docker-compose shows this weird message hiding the real issue.
I just tried to build one of the images with docker build . and then it showed up that some files trying to be included in the cache had no permissions to read and build failed.
Once removed issued files it started working again with no issues.
In my case mounting current dir was the issue as test generate directories with root users on the hosts
So next time build failed because it can't read and start failing build with no clear messsage from docker-compose build.
Need to check user run test to avoid the issue later but hope this helps others to find the real issue.

Regards

add regular users to the docker group

# usermod -a -G docker user
# exit
$ exec $SHELL
$ docker-compose ps

I fixed this by unsetting the CONTAINER_REGISTRY_BASE variable

$ sudo usermod -aG docker $USER

I found it was a missing environment variable that was breaking the image: settings in docker-compose.yml

¯_(ツ)_/¯

the following steps solved the problem for me.

remove docker:
$ sudo apt-get remove docker docker-engine
reinstall with
curl -sSL https://get.docker.com/ | sh

add user to a group:
sudo usermod -aG docker user

Thank You. Uninstalling, then reinstalling and changing user permissions and logging out and logging back in solved it for me.

None of the listed above solutions have fixed it for me. Any other ideas?
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

resolvi o problema com esse comando:

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

This fixed it for me.

I did everything except symbolically linking to docker-compose. Following commands fixed my issue

  1. Add user to docker group (if not already added)
    sudo usermod -aG docker $USER
  2. create a symbolic link to /usr/bin using the following command
    $ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  3. Restart docker service
    $ sudo service docker restart

In my case, none of the above worked

As it turned out, in my compose file I had a camelCase image name (eg imageName), and that was causing Couldn't connect to Docker daemon at http+docker://localunixsocket. Changing that to dash-case solved the problem (very strange).
Docker service was running fine, docker ps and info were also reporting no issues, just launching that compose file was the issue.

Ubuntu 18.04
docker 19.03.6
docker-compose 1.17.1 (compose file version 3)

sudo docker-compose up -d

just faced this issue again and realized I must restart Ubuntu after adding mu user to Docker group

sudo usermod -aG docker user

This by @Kirill-Babkin solved it for me. I had newly created user not in docker group. Thanks.

In my case my docker-compose.yml was missing env var definition on image section

prod-image-generation:
    image: my-image:${BUILD_NUMBER}

I Lost about 30 minutes with it. Please suggest a meaningful error for this

Solution was set a value for the var

Just the empty export worked for me.

export DOCKER_HOST=

Fresh Docker installation here in Ubuntu 18. Assuming your user is already in the docker group, just install the docker service so it autostarts sudo systemctl enable docker then restart and voila sudo init 6

Had the same problem.
Solved on my system by writing "docker-compose build"

I just had the same issue. I found that for some reason my user was not added to the docker security group, in turn not allowing me permission on docker's unix socket and giving me _ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running_.

Adding the docker group to my current user, then logging out and back in again fixed everything for me:
sudo usermod -aG docker $USER

Followed this, then restarted the machine, and ran docker-compose up --build 👍

show

sudo usermod -aG docker $USER

Followed this, then restarted the machine, and ran docker-compose up --build +1

You don't need to restart, a simple re-login should suffice. It did so for me.

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

It's work. don't know why ? haha

Fresh Docker installation here in Ubuntu 18. Assuming your user is already in the docker group, just install the docker service so it autostarts sudo systemctl enable docker then restart and voila sudo init 6

I'm using Manjaro and this solution work for me

thanks @mikemix

I have tried a lot of steps based on the error below after running dockered.

can't initialize iptables table nat': Table does not exist (do you need to insmod?) Perhaps iptables or your kernel needs to be upgraded. (exit status 3)

But Starting Terminal as administrator worked.
sudo service docker start
Remember : The Terminal/Ubuntu on Windows 10 should be launched as Admin

On Ubuntu 20.04 I needed to run

sudo chmod 777 /var/run/docker.sock

and it started working immediately.


⚠️ Edit

Be careful with the command above

This gives any user of that machine full access to a file that's normally owned by root. You may create a severe security hole in your system this way.
@Taranchul

sudo chmod 777 /var/run/docker.sock

This gives _any_ user of that machine full access to a file that's normally owned by root. You may create a severe security hole in your system this way. See https://stackoverflow.com/questions/47854463/docker-got-permission-denied-while-trying-to-connect-to-the-docker-daemon-socke for similar warnings.

As mentioned here and in the link above, sudo usermod -aG docker $USER (or the username in question instead of $USER) should do the trick without undermining the system's security measures.

@Taranchul You are totally right! I always used sudo usermod -aG docker $USER. But unfortunately, sudo usermod -aG docker $USER doesn't seem to work on Ubuntu 20.04 anymore.

Any ideas what could be going wrong?

Alas, I don't. Did you re-login with that user (that worked for me), or restart the machine? I guess that you did so, but better be sure.

Just in case that you or anyone else wants to restore the original permissions of docker.sock, they are 660, at least on my Ubuntu Server 18.04.

@Taranchul Yes I tried re-loging in and rebooting. Didn't work neither on my laptop nor on my workstation.

Maybe it's a 20.04 issue, since its final version was released just yesterday. I normally wait for the first snapshot of any LTS release sometime in the summer, that hopefully has most teething problems fixed by that time.

Could you test it on an older Release?

@Taranchul It seems to be an issue with 20.04. It works fine on 19.04

That's a useful piece of information 👍 although it doesn't help you much at this moment. So, is it an option for you to use 18.04 until 20.04 may become more mature in this matter?

One far shot: Did you check that the user actually was added to the docker group?

@Taranchul I mean I could use 18.04, but since I've migrated everything to 20.04 already I will probably don't do that.

Is running all docker commands with sudo a valid option until it's fixed?

Alas, I don't know much about docker, so I can't answer that question.

I found these instructions to install docker on 20.04 that do it a bit differently: https://www.how2shout.com/how-to/how-to-install-docker-ce-on-ubuntu-20-04-lts-focal-fossa.html

They add the docker group before adding the user. Maybe that's necessery on 20.04? (I don't have it yet, so I can't test it myself.)

sudo groupadd docker
sudo gpasswd -a $USER docker
newgrp docker # or relogin to make the new group known to the system

@Taranchul You know what is weird.... I ran sudo chmod 660 /var/run/docker.sock to reset the permissions and after reboot it is still working.

Can I consider the issue to be fixed or might there still be a security risk?
Maybe I have forgotten a step when I installed everything yesterday... and it's actually not a problem with Ubuntu 20.04?

According to this question on askubuntu.com, docker originally needed sudo to start, but got non-root user usability with version 19.03. In the comments, someone mentiones that without the docker group, the ownership of docker.sock was root:root. Only after creating the docker group, adding the user to it, and restarting the docker server, it changed to root:docker. So, checking if the group exists (edit: and if it does, checking the ownership of docker.sock) seems to be a good idea. Also to restart your docker instance.

Mind one of the lower rated answers there, the one speaking about ACLs and how you may enable access to docker.socks by the command setfacl.

Last, not least, there are warnings about the latter as well as adding a user to the docker group, because it gives that user significant access rights. 😎 But I still think that these ways are preferable to chmod the file's permissions.

Reading your last comment right know after writing the above, I would say just be happy and observe the whole thing. It's hard to tell if you missed something and got it fixed somehow while trying several solutions.

@Taranchul Great. It's still working after restarting Docker. So I guess it was just my fault. Thanks for your help!

@flulu My pleasure, and thanks for taking my first warning as friendly as it was meant. :)

On Windows 10, it was solved by upgrading to WSL2, and backing my Ubuntu Distro to WSL2.
https://docs.microsoft.com/en-us/windows/wsl/wsl2-install

This problem was solved when i restarted the computer. :smile:

This solved my issue.

sudo usermod -aG docker myuser

Thanks, @Kirill-Babkin a lot.

Solved by :

sudo chmod 666 /var/run/docker.sock
sudo chmod 666 /var/run/docker.sock

As said here before, this may open a security hole in your system. Did you try the usermod solution before that? It may rise security concerns, too, because it gives that user complete access over docker, but compared to giving _every_ user access to a root-owned file it seems to be the lesser evil.

@matteo-bombelli
I had the same issue.
You need to restart docker.
$ service docker restart
I solved it with this.

It was the solution and that worked thank you!

i get this error on ubunt 20.0.4

i installed with apt get from apt sources. Is there a newer version in a ppa?

I did
newgrp docker
and it worked

I was working on Lightsail. Rebooting the image fixed it.

Maybe just try to add your Linux user to the group: docker, then relogin.

On Ubuntu 20, docker runs under snap, as you can see via 'systemctl status snap.docker.dockerd.service'

It does attempt to start with the /var/run/docker.sock group set to 'docker', but by default, that group doesn't exist in Ubuntu 20, even if you select the Docker snap in the installation.

To fix this, make the group, add your user to the group, then reboot

sudo groupadd docker
sudo usermod -G docker $USER
sudo reboot

You cannot just logout then login, and as far as I've been able to tell, you can't restart snap.docker.dockerd or snapd itself and have the permissions change. I don't know how to trick it into doing the right thing without rebooting, so if you know, please inform me.

I'm on 20.04 and I had the same issue and could do sudo docker info but not as my regular user. I was in the docker group from before, and can still browse my wordpress site at 127.0.0.1. I had to run newgrp docker to fix it. Very weird because all I have done is lock this workstation since I setup docker 2 days ago. Maybe an update broke something?

newgrp docker works for me

Setting DOCKER_HOST manually worked for me

  1. Find out path to your sock file: (using either sudo service docker status or ps -aef | grep docker)
  2. export DOCKER_HOST=unix://<path to sock file>

In my case sock file was located at /run/containerd/containerd.sock
so i had to run export DOCKER_HOST=unix:///run/containerd/containerd.sock

For my case - After restarting the cluster, issue resolved.

On Ubuntu 20, docker runs under snap, as you can see via 'systemctl status snap.docker.dockerd.service'

It does attempt to start with the /var/run/docker.sock group set to 'docker', but by default, that group doesn't exist in Ubuntu 20, even if you select the Docker snap in the installation.

To fix this, make the group, add your user to the group, then reboot

sudo groupadd docker
sudo usermod -G docker $USER
sudo reboot

You cannot just logout then login, and as far as I've been able to tell, you can't restart snap.docker.dockerd or snapd itself and have the permissions change. I don't know how to trick it into doing the right thing without rebooting, so if you know, please inform me.

I believe you mean sudo usermod -aG docker $USER. Running without -a will cause "If the user is currently a member of a group which is not listed, the user will be removed from the group. "

You cannot just logout then login, and as far as I've been able to tell, you can't restart snap.docker.dockerd or snapd itself and have the permissions change. I don't know how to trick it into doing the right thing without rebooting, so if you know, please inform me.

A relogin should suffice to make the new group active for that user.

This came up for me as well. I needed to disconnect with my nordvpn client for some reason.

sudo docker-compose up -d works!!!

Have you tried without sudo? You shouldn't need it and it could be messing things up in your case. Also, what do you see when you run docker info?

u r a fucking genius. u know that ? Thanks a lot bro . u saved me from hell.

Not sure exactly why, but in my case I had a submodule that wasn't checked out. Running git submodule update --init and then re-running docker-compose build fixed the issue for me

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

Same here. 😃

I just had the same issue. I found that for some reason my user was not added to the docker security group, in turn not allowing me permission on docker's unix socket and giving me _ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running_.

Adding the docker group to my current user, then logging out and back in again fixed everything for me:
sudo usermod -aG docker $USER

also, don't forget to run newgrp docker to get access to that group in your current shell. ref https://stackoverflow.com/a/48569858/2040522

I just had the same issue. I found that for some reason my user was not added to the docker security group, in turn not allowing me permission on docker's unix socket and giving me _ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running_.

Adding the docker group to my current user, then logging out and back in again fixed everything for me:
sudo usermod -aG docker $USER

This works perfectly. You have to relogin to see results.

sudo usermod -aG docker $USER

This works perfectly. You have to relogin to see results.

Alternatively, newgrp docker should do that without a relogin.

sudo chmod 666 /var/run/docker.sock

As said here before, this may open a security hole in your system. Did you try the usermod solution before that? It may rise security concerns, too, because it gives that user complete access over docker, but compared to giving _every_ user access to a root-owned file it seems to be the lesser evil.

You're telling right , but this is very important for devops , i just a developer and i fix that using this command ,
special thank to @shqear93

This is painful and I'm incredulous that the issue has been closed three years ago with no meaningful response from Docker. This github issue shouldn't be in your feature set. What's the plan for straightening this out? Don't punt this to users who don't understand how groups and users and sessions work, or other pieces of software that work the way they do. _You_ chose this complicated way of doing things.

I had to _restart_ my computer instead of logout/login for sudo usermod -aG docker my_user to take effect. Some evidence of this happening to others here: https://unix.stackexchange.com/questions/277240/usermod-a-g-group-user-not-work.

I just had the same issue. I found that for some reason my user was not added to the docker security group, in turn not allowing me permission on docker's unix socket and giving me _ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running_.
Adding the docker group to my current user, then logging out and back in again fixed everything for me:
sudo usermod -aG docker $USER

also, don't forget to run newgrp docker to get access to that group in your current shell. ref https://stackoverflow.com/a/48569858/2040522

Worked perfectly for me. Thanks!

On Ubuntu 16.04 this worked for me:
sudo service docker start && docker-compose up -d

this worked for me!

I just had the same issue. I found that for some reason my user was not added to the docker security group, in turn not allowing me permission on docker's unix socket and giving me _ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running_.
Adding the docker group to my current user, then logging out and back in again fixed everything for me:
sudo usermod -aG docker $USER

also, don't forget to run newgrp docker to get access to that group in your current shell. ref https://stackoverflow.com/a/48569858/2040522

This solved my problem, thanks!!!

I have no idea why, but what fixed it for me was removing the following line from my docker-compose .env file:

DOCKER_HOST=tcp://localhost:2375

Solved by :

sudo chmod 666 /var/run/docker.sock

Thanks. Solved in Ubuntu 20.0.4 LTS

I just got tried of playing with permissions and just did:

sudo docker-compose build

And it was off to the races.
At the heart of it a permissions issue, if have have the docker service running, group assigned, socket permissions all set, and still didn't see it working. Just do it with sudo. Worked for me, have better things to do.

any solution for ubuntu 20.04?

any solution for ubuntu 20.04?

Did you try the solution posted before? (https://github.com/docker/compose/issues/4181#issuecomment-629748049)

In short (with added later suggestions):

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

If "newgrp docker" doesn't suffice, a reboot may be neccessary (there are conflicting comments about that).

Was this page helpful?
0 / 5 - 0 ratings