154

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.

2
  • Do you have the $DOCKER_HOST environment variable set? Is the Docker Desktop application running? Commented Nov 3, 2020 at 12:08
  • No current answers here helped me to resolve. Commented Nov 15, 2021 at 21:59

17 Answers 17

251

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
Sign up to request clarification or add additional context in comments.

3 Comments

What worked for me: resetting the docker, navigate to my projectfolder and do docker-compose up again.
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.
This actual worked for me , I also added an upvote.
73

just open Docker Desktop on your computer

7 Comments

Not a solution for cloud-based systems
Does not work on ubuntu Linux
This actually worked for me on MacOS Catalina.
I don't know why but it worked for me on ubuntu 22.04
@Noob btw docker desktop does exist on ubuntu linux
|
65
sudo chmod 666 /var/run/docker.sock

This worked for me

3 Comments

This is extremely unsafe. FYI, giving a user access to docker.sock is like giving them sudo
"extremely unsafe" and whatever, but works.
Obviously this, is not meant to be in a production server or something like that, just for testing/local purposes.
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

1 Comment

systemctl is-enabled docker should show if docker is disabled or not
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?

Comments

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.

2 Comments

Doesn't work for me.
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.
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

1 Comment

service docker start worked in wsl, also can restart docker desktop / service in OS
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!

Comments

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.

1 Comment

For those having issue on MacOS, this solution works for me - leighmcculloch.com/posts/docker-context-via-ssh-with-macos
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/

Comments

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.

1 Comment

thanks! works for me. I also tried almost solutions above.... but none of them worked.
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

Comments

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

Comments

0

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

enter image description here

Comments

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

Comments

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.

Comments

0

Just run your command with sudo to give privileges to docker-compose command to run.

I just faced the same problem. I was able to run with sudo docker-compose up on Ubuntu (WSL).

Comments