Docker-compose up: 获取服务器 API 版本时出错: (“连接中止”,ConnectionRefusedError (61,“连接被拒绝”))

我正试图在我的终端中执行 docker-compose up命令。首先我导航到文件目录,在那里我找到一个 docker-compose。Yaml.然后我写命令。服务器在80端口上。我得到以下错误:

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

第一个错误出现两次,然后是第二个。

105197 次浏览

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

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

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.

just open Docker Desktop on your computer

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?

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.

sudo chmod 666 /var/run/docker.sock

This worked for me

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

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/

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.