Skip to content

DockerException: Error while fetching server API version #2717

Open

Description

@dazza-codes

Could be a bug in 4.4.0 release?

self = <docker.api.client.APIClient object at 0x7f8b52ceec90>

    def _retrieve_server_version(self):
        try:
            return self.version(api_version=False)["ApiVersion"]
        except KeyError:
            raise DockerException(
                'Invalid response from docker daemon: key "ApiVersion"'
                ' is missing.'
            )
        except Exception as e:
            raise DockerException(
>               'Error while fetching server API version: {0}'.format(e)
            )
E           docker.errors.DockerException: Error while fetching server API version: cannot unpack non-iterable CallbackResponse object

/opt/conda/envs/project/lib/python3.7/site-packages/docker/api/client.py:222: DockerException

versions

$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"

$ docker --version
Docker version 19.03.14, build 5eb3275d40

$ service docker status
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-12-03 16:13:07 PST; 1h 26min ago
     Docs: https://docs.docker.com
 Main PID: 1844 (dockerd)
    Tasks: 10
   CGroup: /system.slice/docker.service
           └─1844 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

$ python --version
Python 3.7.8

$ poetry --version
Poetry version 1.1.4

$ poetry show docker
name         : docker
version      : 4.4.0
description  : A Python library for the Docker Engine API.

dependencies
 - pywin32 227
 - requests >=2.14.2,<2.18.0 || >2.18.0
 - six >=1.4.0
 - websocket-client >=0.32.0

Activity

  1. aiordache commented on Dec 4, 2020

    @aiordache
    Contributor

    Can you provide the output from docker version please?
    Try to run this to simulate what the server version retrieval method does:

    $ curl -s --unix-socket /var/run/docker.sock  http://localhost/version | jq '.ApiVersion'
    "1.41"
    

    To avoid this automatic version retrieval, please set the API version to use when you instantiate the docker client.

  2. dazza-codes commented on Dec 4, 2020

    @dazza-codes
    Author
    $ curl -s --unix-socket /var/run/docker.sock  http://localhost/version | jq '.ApiVersion'
    "1.40"
    
    $ docker version
    Client: Docker Engine - Community
     Version:           19.03.14
     API version:       1.40
     Go version:        go1.13.15
     Git commit:        5eb3275d40
     Built:             Tue Dec  1 19:20:17 2020
     OS/Arch:           linux/amd64
     Experimental:      false
    
    Server: Docker Engine - Community
     Engine:
      Version:          19.03.14
      API version:      1.40 (minimum version 1.12)
      Go version:       go1.13.15
      Git commit:       5eb3275d40
      Built:            Tue Dec  1 19:18:45 2020
      OS/Arch:          linux/amd64
      Experimental:     false
     containerd:
      Version:          1.3.9
      GitCommit:        ea765aba0d05254012b0b9e595e995c09186427f
     runc:
      Version:          1.0.0-rc10
      GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
     docker-init:
      Version:          0.18.0
      GitCommit:        fec3683
    

    From curl -s --unix-socket /var/run/docker.sock http://localhost/version | jq:

    {
      "Platform": {
        "Name": "Docker Engine - Community"
      },
      "Components": [
        {
          "Name": "Engine",
          "Version": "19.03.14",
          "Details": {
            "ApiVersion": "1.40",
            "Arch": "amd64",
            "BuildTime": "2020-12-01T19:18:45.000000000+00:00",
            "Experimental": "false",
            "GitCommit": "5eb3275d40",
            "GoVersion": "go1.13.15",
            "KernelVersion": "4.15.0-126-generic",
            "MinAPIVersion": "1.12",
            "Os": "linux"
          }
        },
        {
          "Name": "containerd",
          "Version": "1.3.9",
          "Details": {
            "GitCommit": "ea765aba0d05254012b0b9e595e995c09186427f"
          }
        },
        {
          "Name": "runc",
          "Version": "1.0.0-rc10",
          "Details": {
            "GitCommit": "dc9208a3303feef5b3839f4323d9beb36df0a9dd"
          }
        },
        {
          "Name": "docker-init",
          "Version": "0.18.0",
          "Details": {
            "GitCommit": "fec3683"
          }
        }
      ],
      "Version": "19.03.14",
      "ApiVersion": "1.40",
      "MinAPIVersion": "1.12",
      "GitCommit": "5eb3275d40",
      "GoVersion": "go1.13.15",
      "Os": "linux",
      "Arch": "amd64",
      "KernelVersion": "4.15.0-126-generic",
      "BuildTime": "2020-12-01T19:18:45.000000000+00:00"
    }
  3. null-sleep commented on Jul 12, 2021

    @null-sleep

    Having the same issue:

    $ curl -s --unix-socket /var/run/docker.sock  http://localhost/version | jq '.ApiVersion'
    "1.41"
    $ docker version
    Client:
     Cloud integration: 1.0.17
     Version:           20.10.7
     API version:       1.41
     Go version:        go1.16.4
     Git commit:        f0df350
     Built:             Wed Jun  2 11:56:22 2021
     OS/Arch:           darwin/amd64
     Context:           desktop-linux
     Experimental:      true
    
    Server: Docker Engine - Community
     Engine:
      Version:          20.10.7
      API version:      1.41 (minimum version 1.12)
      Go version:       go1.13.15
      Git commit:       b0f5bc3
      Built:            Wed Jun  2 11:54:58 2021
      OS/Arch:          linux/amd64
      Experimental:     false
     containerd:
      Version:          1.4.6
      GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
     runc:
      Version:          1.0.0-rc95
      GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
     docker-init:
      Version:          0.19.0
      GitCommit:        de40ad0
    
    $ curl -s --unix-socket /var/run/docker.sock http://localhost/version | jq
    {
      "Platform": {
        "Name": "Docker Engine - Community"
      },
      "Components": [
        {
          "Name": "Engine",
          "Version": "20.10.7",
          "Details": {
            "ApiVersion": "1.41",
            "Arch": "amd64",
            "BuildTime": "2021-06-02T11:54:58.000000000+00:00",
            "Experimental": "false",
            "GitCommit": "b0f5bc3",
            "GoVersion": "go1.13.15",
            "KernelVersion": "5.10.25-linuxkit",
            "MinAPIVersion": "1.12",
            "Os": "linux"
          }
        },
        {
          "Name": "containerd",
          "Version": "1.4.6",
          "Details": {
            "GitCommit": "d71fcd7d8303cbf684402823e425e9dd2e99285d"
          }
        },
        {
          "Name": "runc",
          "Version": "1.0.0-rc95",
          "Details": {
            "GitCommit": "b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7"
          }
        },
        {
          "Name": "docker-init",
          "Version": "0.19.0",
          "Details": {
            "GitCommit": "de40ad0"
          }
        }
      ],
      "Version": "20.10.7",
      "ApiVersion": "1.41",
      "MinAPIVersion": "1.12",
      "GitCommit": "b0f5bc3",
      "GoVersion": "go1.13.15",
      "Os": "linux",
      "Arch": "amd64",
      "KernelVersion": "5.10.25-linuxkit",
      "BuildTime": "2021-06-02T11:54:58.000000000+00:00"
    }
    
  4. elboulangero commented on Sep 23, 2021

    @elboulangero

    I'm having the same issue.

    I noticed a change in the behavior of docker-py between version 4.2 and 4.3, caused by 727080b

    Before this change, the client was created with an API version set to 1.35 by default. After this change, there's no more default, and the client retrieve this version from the docker daemon. So at this points the clients needs to talk to the docker daemon.

    In practice, it means that prior to this change, a user that is NOT part of the docker group could still run docker.from_env() successfully. After this change it's not possible anymore. If user doesn't have the permission to talk to the daemon, docker.from_env() throw this exception:

        Error: Error while fetching server API version: ('Connection aborted.', PermissionError(13, 'Permission denied'))
    

    I wonder if it would be possible to get something a bit more precise than a DockerException in that case? I need to handle this case, and right now the only way is to look for `permission denied' in the error message, or something like that. It works, but matching bits of strings in an error message is usually not the right thing to do.

  5. motin commented on Nov 1, 2023

    @motin

    Thanks for these comments (and those in @tillahoffmann's linked issue), they helped my colleague get his local setup working. The trick was to enable this setting:
    image

  6. katewapo commented on May 30, 2024

    @katewapo

    I have the same problem. Which App/GUI is it that the screenshot shows?

  7. ThisDoctor commented on Aug 21, 2024

    @ThisDoctor

    Thanks for these comments (and those in @tillahoffmann's linked issue), they helped my colleague get his local setup working. The trick was to enable this setting: image

    I had the same problem and had to activate the "Allow privileged port mapping" option in the advanced settings.

  8. jbonnier commented on Apr 28, 2025

    @jbonnier

    Not using Docker Desktop anyone has a fix so far?

  9. ksyblast commented on Apr 28, 2025

    @ksyblast

    Not using Docker Desktop anyone has a fix so far?

    Hi! For me upgrading requests library was a fix

  10. jbonnier commented on May 1, 2025

    @jbonnier

    Not using Docker Desktop anyone has a fix so far?

    Hi! For me upgrading requests library was a fix

    Oh wow! Updating the requests lib on the target did it for me as well.

    Thanks mate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions