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

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!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 247
  • Comments: 225

Most upvoted 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.

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

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

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.

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

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

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

@ssi-anik that’s computer science 😄

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.

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

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.

👇🏻👇🏻👇🏻👇🏻👇🏻👇🏻 👉🏽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

@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

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

can anyone consolidate the solution for this problem in steps ?

Solved by :

sudo chmod 666 /var/run/docker.sock

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

Solved by :

sudo chmod 666 /var/run/docker.sock

Thanks. Solved in Ubuntu 20.0.4 LTS

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.

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

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

thx!

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

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.

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 😕

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

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

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.

chmod 777 it

sudo docker-compose up -d works!!!

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

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 was facing this similar issue on Ubuntu. The below command solved my problem.

sudo chmod 666 /var/run/docker.sock

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

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

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

I was getting Couldn't connect to Docker daemon at http+docker://localhost - is it running? which turned out to be a syntax error in my compose file due to a dynamic variable not being passed.

Running docker-compose config -f my-docker-compose-file.yml showed me that it was missing.

I was using the following dynamic value which I forgot to set in my shell before running docker-compose and wasn’t warned about:

...
image: image-name:${TAG}
...

To avoid getting docker-compose’s generic error, you can do this instead so that you are warned when a dynamic value is not found:

...
image: image-name:${TAG?TAG value is required}
...

I did newgrp docker and it worked

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.

just type sudo before your docker-compose command!

@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

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

This works.

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.

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

just use sudo

Sudo shouldn’t be necessary, did you try the solution posted here before?

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

After that, docker commands should work without sudo.

This solved my issue.

sudo usermod -aG docker myuser

Thanks, @Kirill-Babkin a lot.

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 docker-compose up -d

just type sudo before your docker-compose command!

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

try this add sudo thats it

sudo docker-compose up

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

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.

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

I was getting Couldn't connect to Docker daemon at http+docker://localhost - is it running? which turned out to be a syntax error in my compose file due to a dynamic variable not being passed.

Running docker-compose config -f my-docker-compose-file.yml showed me that it was missing.

I was using the following dynamic value which I forgot to set in my shell before running docker-compose and wasn’t warned about:

...
image: image-name:${TAG}
...

To avoid getting docker-compose’s generic error, you can do this instead so that you are warned when a dynamic value is not found:

...
image: image-name:${TAG?TAG value is required}
...

This issue still exists in docker-compose version 1.27.4, build 40524192:

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

Had nothing to do with any of the solutions listed above - it was a right ole red-herring chase for me! 😄

While docker-compose config parses the file successfully, docker-compose build will fail.

For me it was a double slash // in my docker-compose.yml file, in the image: entry that caused the issue…

If ${DOCKER_USER} or ${DOCKER_IMAGE_NAME} cause a double slash / then docker-compose build will fail:

...
    image: ${DOCKER_USER}/${DOCKER_IMAGE_NAME}:${DOCKER_TAG}
...

Removing the superfluous slash / fixed the problem for me. (I actually trail the / in ${DOCKER_USER} so that I can omit the user portion of the image: URI if necessary without breaking the build.)

Many thanks to @sheedy for the hint! 😉

Can we fix the docker-compose config parser please, and wave goodbye to this issue? 😄 👍

Additional info:

docker info
Client:
 Debug Mode: false

Server:
 Containers: 8
  Running: 8
  Paused: 0
  Stopped: 0
 Images: 55
 Server Version: 19.03.13
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ea765aba0d05254012b0b9e595e995c09186427f
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.8.0-0.bpo.2-amd64
 Operating System: Debian GNU/Linux 10 (buster)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 15.6GiB
 Name: omv.localdomain
 ID: WY5F:C62I:HKE4:LXKX:B7US:SVZF:GN55:L6SF:HIO2:CDZW:64UZ:J6MY
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
docker version
Client: Docker Engine - Community
 Version:           19.03.13
 API version:       1.40
 Go version:        go1.13.15
 Git commit:        4484c46d9d
 Built:             Wed Sep 16 17:02:55 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.13
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       4484c46d9d
  Built:            Wed Sep 16 17:01:25 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.3.9
  GitCommit:        ea765aba0d05254012b0b9e595e995c09186427f
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
docker-compose version
docker-compose version 1.27.4, build 40524192
docker-py version: 4.3.1
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

newgrp docker works for me

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

commands:

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

This worked for me:

sudo usermod -aG docker $(whoami)

logout

login

check to be sure you are in the “docker” group.

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

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.

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

systemctl restart docker resolve it

Ubuntu 20.0.4 LTS

Initially with this command

docker-compose up

I got the same error.

Then I saw the comment about changing the permissions on docker.sock Then this worked:

sudo docker-compose up

Then I saw the comment about Ubuntu not adding the user to the docker group, so I returned the docker.sock file to its original permissions:

sudo chmod 660 /var/run/docker.sock

and then I did

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

and then this worked:

docker-compose up

docker-compose build

Use sudo docker-compose build

sudo usermod -aG docker $USER

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

Alternatively, newgrp docker should do that without a 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.

This problem was solved when i restarted the computer. 😄

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

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.

add regular users to the docker group

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

that command solves to me:

sudo usermod -aG docker user

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

$ sudo service docker start
$ sudo service docker status

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.

It worked after I restarted the server 😃

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.

@ramblinwreck35 Edited my comment as you pointed. 👍

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

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.

Sometimes, the error comes when the Image name contains uppercase characters…

service-name: image: Abcd/Xyz build: …

corrected compose file

service-name: image: abcd/xyz build: …

hey i’m late to the party I know but for anyone who gets this error on a live server just log out and back in again. When you add your user to the docker group you need to reload your terminal to get the updated permissions.

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

This makes the file writable by every user which is a potential security risk in a system directory. That should only be considered as a last resort after trying the safer solution posted here before:

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

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.

just use sudo

Sometimes I wish error messages were more helpful.

But yeah, quick google search for error, scrolling to find an answer that has the most emoji reactions and it works 🎉

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

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!!!

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

this worked for me!

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

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

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

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

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 It seems to be an issue with 20.04. It works fine on 19.04

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

Just the empty export worked for me.

export DOCKER_HOST=

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

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.

I fixed this by unsetting the CONTAINER_REGISTRY_BASE variable

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.

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

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

and it worked!

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

Hi ,

problem solved with sudo before the command 😉 ,

Thanks, Moatez

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

sudo usermod -a -G docker theUser

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.

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

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

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

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.

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

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

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.

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

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 🍰).

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

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

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.

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.