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

2022-08-30 07:48:10

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

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

第一个错误显示两次,然后是第二次。


答案 1

将用户添加到 Docker 组,然后重试。

sudo gpasswd -a $USER docker
newgrp docker

如果问题仍然存在,可以在注销后尝试并重新登录,或重新启动。或者干脆做:

sudo su $USER

注意:如果您的计算机上未运行 docker,也可能发生这种情况。对于带有系统服务管理器的 linux,您可以使用命令进行验证:

systemctl status docker.service

答案 2

只需在计算机上打开 Docker Desktop


推荐