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
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 rundocker info
?Try running
dockerd
orsudo dockerd
if required first to start daemon. If you startdockerd
withsudo
you may want to rundocker-compose up
withsudo
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:
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 withcurl -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:
Calling
docker-compose build
results in:So I tried to use Docker to build each file individually:
This gave me a more useful error:
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:
thank you @jamethy, I,ve done just right that and i get
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 toCOPY
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 todocker
groupnewgrp docker
# activates new permissions fordocker
group@shin- Hello! I’ve already done it with with sudo and also using root (
sudo su
).here is the operation made as root
this is the result of
docker info
@harshajayaweeraXHJ
dockerd
does not work butsudo service docker start
works as expectedPS:
@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 :
On Ubuntu 16.04 this worked for me:
sudo service docker start && docker-compose up -d
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.thx!
resolvi o problema com esse comando:
sudo chown $USER:docker /var/run/docker.sock
Needed all of:
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:
but this number should be created by docker itself
I was facing this similar issue on Ubuntu. The below command solved my problem.
that’s the correct solution
Setting
DOCKER_HOST
manually worked for mesudo service docker status
orps -aef | grep docker
)DOCKER_HOST=unix://<path to sock file>
In my case sock file was located at
/run/containerd/containerd.sock
so i had to runexport 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, orsudo su - ${USER}
to receive the updated config in your terminalsame 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: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:
I did
newgrp docker
and it workedIs 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
u r a fucking genius. u know that ? Thanks a lot bro . u saved me from hell.
just type
sudo
before yourdocker-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
This works.
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
Sudo shouldn’t be necessary, did you try the solution posted here before?
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.
Thanks, @Kirill-Babkin a lot.
On Ubuntu 20.04 I needed to run
and it started working immediately.
⚠️ Edit
Be careful with the command above
sudo docker-compose up -d
Take your like, sir! omg…, but works fine for me, great job!
try this add sudo thats it
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:
"$GIT_BRANCH-$RANDOMISH_HASH"
and curious part is that it truncates string from the beginning.-
), and the resulting directory name generated by Jenkins ended up starting with-
.docker-compose
in that folder, and by default docker-compose uses directory name as a prefix to name containers.-
) and that appears to be an illegal character for a docker container’s name to start with.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: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. Usingservice docker start
then allowed me to run the info command. This is what I got:This issue still exists in
docker-compose version 1.27.4, build 40524192
: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 mydocker-compose.yml
file, in theimage:
entry that caused the issue…If
${DOCKER_USER}
or${DOCKER_IMAGE_NAME}
cause a double slash/
thendocker-compose build
will fail: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 theimage:
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:
newgrp docker
works for meResolved the issue with this:
sudo usermod -aG docker $USER
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:
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 itUbuntu 20.0.4 LTS
Initially with this command
I got the same error.
Then I saw the comment about changing the permissions on docker.sock Then this worked:
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:
and then I did
and then this worked:
Use sudo docker-compose build
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?
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
https://www.digitalocean.com/community/tutorials/docker-ubuntu-18-04-1-ru
that command solves to me:
sudo usermod -aG docker user
Hello, got same error message:
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 tohttp+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/.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.
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:
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:This solved my problem, thanks!!!
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.This works perfectly. You have to relogin to see results.
also, don’t forget to run
newgrp docker
to get access to that group in your current shell. ref https://stackoverflow.com/a/48569858/2040522I 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
wasroot:root
. Only after creating the docker group, adding the user to it, and restarting the docker server, it changed toroot:docker
. So, checking if the group exists (edit: and if it does, checking the ownership ofdocker.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 commandsetfacl
.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 autostartssudo systemctl enable docker
then restart and voilasudo init 6
Just the empty export worked for me.
I did everything except symbolically linking to docker-compose. Following commands fixed my issue
sudo usermod -aG docker $USER
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
$ sudo service docker restart
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
variableThe 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 rundocker-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:Which should just have said:
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 worktl;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:
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 supplyingbuild: ./
. When we removedbuild: ./
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 ofdocker-compose run ...
withoutsudo
from$USER
user shell. (Thanks, @Kirill-Babkin 🍰).@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 aroot
-owned directory into one of the containers. For some reason that preventeddocker-compose
(which runsdocker 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 by999
anddocker
group, the weird part is that it wasn’t even for the image I was trying to build, it was a separate service.