docker / compose

Define and run multi-container applications with Docker
https://docs.docker.com/compose/
Apache License 2.0
33.89k stars 5.21k forks source link

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

Closed matteo-bombelli closed 7 years ago

matteo-bombelli commented 7 years ago

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 think that I've tried all the possible configurations am I right?


Specs:


Thank You!

shin- commented 7 years ago

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?

harshajayaweeraXHJ commented 7 years ago

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 commented 7 years ago

@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

jamethy commented 7 years ago

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.

matteo-bombelli commented 7 years ago

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
jorgeas80 commented 7 years ago

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

matteo-bombelli commented 7 years ago

for me the problem stays there:

Bind address needs a port: 127.0.0.1

but this number should be created by docker itself

elikane commented 7 years ago

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
shin- commented 7 years ago

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

ippo012 commented 7 years ago

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

shashijais789 commented 7 years ago

can anyone consolidate the solution for this problem in steps ?

lalitkumarj commented 7 years ago

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

furkanmustafa commented 7 years ago

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

shin- commented 7 years ago

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

mrjameshamilton commented 7 years ago

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

Kirill-Babkin commented 7 years ago

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

alberto56 commented 7 years ago

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.
kwmartin commented 7 years ago

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.

denis-kalinin commented 7 years ago

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.

zazaian commented 7 years ago

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

ssi-anik commented 7 years ago

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

matteo-bombelli commented 7 years ago

@ssi-anik that's computer science 😄

desertcrystal commented 7 years ago

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

jhnoor commented 7 years ago

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.

a1ec commented 7 years ago

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.

hk0i commented 6 years ago

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.

trevorjamesmartin commented 6 years ago

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

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.

ax003d commented 6 years ago

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.

wawastein commented 6 years ago

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.

lautjy commented 6 years ago

@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

chrvsprasad commented 6 years ago

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

chrvsprasad commented 6 years ago

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

Regards, Prasad RVS

chrvsprasad commented 6 years ago

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

manjukori commented 6 years ago

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.

arikkfir commented 6 years ago

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

arikkfir commented 6 years ago

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.

crosspluser commented 6 years ago

chmod 777 it

christianhanne commented 6 years ago

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.

leogomesdev commented 6 years ago

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

aJetHorn commented 6 years ago

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

yoloseem commented 6 years ago

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

ramblinwreck35 commented 6 years ago

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

yoloseem commented 6 years ago

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

blair-anson commented 6 years ago

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

cheerego commented 6 years ago

systemctl restart docker resolve it

hsali commented 6 years ago

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

hsali commented 6 years ago

I used sudo. problem solved.

uniquestring commented 6 years ago

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.

mikeantonelli commented 6 years ago

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

jlouisfoster commented 6 years ago

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