Docker-compose up : Error while fetching server API version: ('Connection aborted.', ConnectionRefusedError(61, 'Connection refused'))
Asked Answered
D

16

142

I am trying to do the docker-compose up command in my terminal. First I navigate to the file directory where I find a docker-compose.yaml. Then I write the command. The Server is on Port 80. I get the following error:

Traceback (most recent call last):
      File "site-packages/docker/api/client.py", line 205, in _retrieve_server_version
      File "site-packages/docker/api/daemon.py", line 181, in version
      File "site-packages/docker/utils/decorators.py", line 46, in inner
      File "site-packages/docker/api/client.py", line 228, in _get
      File "site-packages/requests/sessions.py", line 543, in get
      File "site-packages/requests/sessions.py", line 530, in request
      File "site-packages/requests/sessions.py", line 643, in send
      File "site-packages/requests/adapters.py", line 498, in send
    requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionRefusedError(61, 'Connection refused'))
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "docker-compose", line 3, in <module>
      File "compose/cli/main.py", line 67, in main
      File "compose/cli/main.py", line 123, in perform_command
      File "compose/cli/command.py", line 69, in project_from_options
      File "compose/cli/command.py", line 132, in get_project
      File "compose/cli/docker_client.py", line 43, in get_client
      File "compose/cli/docker_client.py", line 170, in docker_client
      File "site-packages/docker/api/client.py", line 188, in __init__
      File "site-packages/docker/api/client.py", line 213, in _retrieve_server_version
    docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', ConnectionRefusedError(61, 'Connection refused'))
    [12728] Failed to execute script docker-compose

The first error shows up two times then the second.

Dormouse answered 3/11, 2020 at 11:55 Comment(3)
Do you have the $DOCKER_HOST environment variable set? Is the Docker Desktop application running?Getaway
I tried: fiona@Fionas-MacBook-Pro gruppe-13 % docker run -d -p 80:80 docker/getting-started b35edd4bbab8ec87a0ef2beb793c4bb3382d5b878949bddca096ca1374bd84e9 docker: Error response from daemon: driver failed programming external connectivity on endpoint modest_agnesi (097923b153f0c23cb738591b39fff9c90479e4026add561cc847124d71b8b888): Bind for 0.0.0.0:80 failed: port is already allocated. Do you have an idea?Dormouse
No current answers here helped me to resolve.Overstretch
F
236

Add your user to docker group and try again.

sudo gpasswd -a $USER docker
newgrp docker

If you still have the problem, you may try after logging out and login back, or reboot. Or simply do:

sudo su $USER

Note: this may also happens if docker is not running on your machine. For linux with sytemd service manager, you could verify using command:

systemctl status docker.service
Falcone answered 10/12, 2020 at 18:18 Comment(3)
What worked for me: resetting the docker, navigate to my projectfolder and do docker-compose up again.Dormouse
Why in this order? I would have thought you would at first need to make a new group "docker" and then add the user to that group. If you check it with the command groups after the sudo gpasswd -a $USER docker, there is still no such group as "docker", it gets made by the newgrp docker in the end. Still works. Seems to map the user as the member of the group at first and matches that group name afterwards with any new group.Clank
This actual worked for me , I also added an upvote.Oscillatory
C
71

just open Docker Desktop on your computer

Convolvulus answered 6/3, 2021 at 14:4 Comment(7)
Not a solution for cloud-based systemsCosmic
Does not work on ubuntu LinuxGlabrous
This actually worked for me on MacOS Catalina.Amoreta
I don't know why but it worked for me on ubuntu 22.04Slipon
@Glabrous btw docker desktop does exist on ubuntu linuxSpoiler
This worked for me on Ubuntu 22.04 while no other option workedLyndy
well the docker desktop does exist. but don't use it if you have used something else. it does strange things to environment, creates new docker env. actually it is the cause of why I look at this question.Sabbat
S
60
sudo chmod 666 /var/run/docker.sock

This worked for me

Subsoil answered 17/11, 2021 at 11:5 Comment(3)
This is extremely unsafe. FYI, giving a user access to docker.sock is like giving them sudoFrivolous
"extremely unsafe" and whatever, but works.Glazer
Obviously this, is not meant to be in a production server or something like that, just for testing/local purposes.Glazer
F
14

I had the same issue and error message. In my case i had to start and enable docker service.

systemctl start docker
systemctl enable docker
Futurism answered 19/12, 2020 at 17:22 Comment(1)
systemctl is-enabled docker should show if docker is disabled or notBudd
B
11

Make sure your docker is actually running on your machine. You can use this post: How to check if the docker engine and a docker container are running?

Bowes answered 14/3, 2021 at 1:55 Comment(0)
B
10

To add clarity to Zstack's answer.

I encountered this issue while trying to setup Ansible AWX on Ubuntu 20.04

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error connecting: Error while fetching server API version: ('Connection aborted.', PermissionError(13, 'Permission denied'))"} ...ignoring

Here's how I fixed it:

The issue was caused because I had not added my current user to the docker group.

Create the docker group if it does not already exist.

sudo groupadd docker

Add your user to the docker group.

sudo usermod -aG docker $USER

Log out and log back in so that your group membership is re-evaluated.

Verify that you can run docker commands without sudo.

docker ps

That's all.

Bandolier answered 23/8, 2021 at 18:1 Comment(2)
Doesn't work for me.Overstretch
I did not need the first command sudo groupadd docker, I guess that docker group is there by default. Then I ran sudo usermod -aG docker myuser (your code with $USER is better) and sg docker -c "bash" and it worked. I am not sure whether the latter command was needed, someone can comment if so.Clank
C
7

Solution: This means you haven’t started your docker service!

First, try to start it using

1.sudo systemctl start docker

2.sudo service docker start

3.sudo /etc/init.d/docker restart

For More Info see this docs:here

Curtcurtail answered 5/12, 2021 at 14:25 Comment(1)
service docker start worked in wsl, also can restart docker desktop / service in OSHow
M
3

The error happend to me in production and linux machines, specially with amazon ec2 instances.

As a simple and safe solution:

First (of course, if using linux machines and systemd):

sudo systemctl enable docker.service
sudo systemctl start docker.service
sudo usermod -aG docker <here-your-user>

Make sure you logout and login again. Then, give executable permissions to docker compose binary:

sudo chmod +x /usr/local/bin/docker-compose

Try again!

Machzor answered 24/5, 2023 at 19:52 Comment(0)
V
2

I had the same error after system and Docker updates on macOS Big Sur 11.1. I was also unable to run Docker Desktop, so I've checked the option open at login and simply restarted the system.

Vardar answered 6/1, 2021 at 10:58 Comment(1)
For those having issue on MacOS, this solution works for me - leighmcculloch.com/posts/docker-context-via-ssh-with-macosIty
S
2

This problem occurs due to docker user has no right access ,

After giving the right permissions and reconnecting to the server should solve the issue,

You can create the docker user if not exist

sudo groupadd docker

Add docker user to user group

usermod -aG docker $USER

Then reconnect to the server, it should work.

For more information this link is usefull : https://docs.docker.com/engine/install/linux-postinstall/

Sanitize answered 2/2, 2022 at 5:47 Comment(0)
M
2

I tried almost all the solutions above but for some reason what worked for me was sourcing the bashrc file:

source ~/.bashrc.

After this the error went away.

Meadowsweet answered 2/3, 2022 at 5:8 Comment(1)
thanks! works for me. I also tried almost solutions above.... but none of them worked.Trenton
W
1

you can give docker socket read and write permission for other users by executing this command in your machine

sudo chmod o+rw /var/run/docker.sock
Walz answered 25/5, 2023 at 7:0 Comment(0)
L
0

I've just encountered this problem on my Mac after upgrading to 4.17.0. I solved the problem by downgrading again to 4.16.2 from https://docs.docker.com/desktop/release-notes/.

Longford answered 16/3, 2023 at 13:51 Comment(0)
B
0

For who is using WSL, make sure the WSL settings enabled, and restart Docker Desktop

enter image description here

Barbados answered 6/7, 2023 at 7:45 Comment(0)
S
0

I got this error after running Docker Desktop once, and it was because it changed my context and thus the Docker endpoint being used

I fixed it by running this command

docker context use default

You can also list your contexts with docker context list

Simon answered 22/9, 2023 at 19:8 Comment(0)
F
0

happened to me as well when i tried

docker-compose up

without sudo. When added sudo command to start of that command things work fine in windows wsl. A file permission thing it seem.

Furman answered 16/2 at 0:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.