129

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.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
blackSwan566
  • 1,421
  • 2
  • 6
  • 10
  • Do you have the `$DOCKER_HOST` environment variable set? Is the Docker Desktop application running? – David Maze Nov 03 '20 at 12:08
  • 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? – blackSwan566 Nov 03 '20 at 13:54
  • No current answers here helped me to resolve. – Eugene Gr. Philippov Nov 15 '21 at 21:59

14 Answers14

214

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
Zstack
  • 4,046
  • 1
  • 19
  • 22
  • 2
    What worked for me: resetting the docker, navigate to my projectfolder and do docker-compose up again. – blackSwan566 Jan 09 '21 at 11:58
  • 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. – questionto42 Jul 29 '22 at 23:15
71

just open Docker Desktop on your computer

slideWXY
  • 1,121
  • 8
  • 9
56
sudo chmod 666 /var/run/docker.sock

This worked for me

Abdulhakim
  • 655
  • 6
  • 9
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
koolwithk
  • 685
  • 8
  • 14
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?

bisamov
  • 650
  • 1
  • 8
  • 24
9

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.

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
  • 1
    Doesn't work for me. – Eugene Gr. Philippov Nov 15 '21 at 21:58
  • 1
    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. – questionto42 Jul 27 '22 at 16:32
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

AthulMuralidhar
  • 662
  • 1
  • 9
  • 26
cng.buff
  • 405
  • 4
  • 5
  • `service docker start` worked in `wsl`, also can restart docker desktop / service in OS – Jason Jul 13 '22 at 18:46
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.

mpro
  • 14,302
  • 5
  • 28
  • 43
  • For those having issue on MacOS, this solution works for me - https://leighmcculloch.com/posts/docker-context-via-ssh-with-macos/ – kctang Nov 01 '21 at 15:19
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/

Murad Shukurlu
  • 417
  • 6
  • 11
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.

anosha_rehan
  • 1,522
  • 10
  • 17
1

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!

Caesar
  • 11
  • 2
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/.

Alexander Pacha
  • 9,187
  • 3
  • 68
  • 108
0

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
Mohammed Ashraf
  • 110
  • 1
  • 6
0

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

enter image description here

Yitong Feng
  • 243
  • 3
  • 9