Skip to content

Docker CLI contexts not used or supported #3146

Open
@brettdh

Description

Testing with Docker Desktop on a mac, I have this docker context state:

➜ docker context list
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                       KUBERNETES ENDPOINT   ORCHESTRATOR
colima              moby                colima                                    unix:///Users/brhiggins/.colima/default/docker.sock
default             moby                Current DOCKER_HOST based configuration   unix:///var/run/docker.sock
desktop-linux *     moby                                                          unix:///Users/brhiggins/.docker/run/docker.sock

The desktop-linux context is active, and /var/run/docker.sock does not exist. docker version correctly uses the active context and returns the server version info. However, docker.from_env() throws an error:

../../../.pyenv/versions/3.11.4/envs/myproj/lib/python3.11/site-packages/docker/client.py:96: in from_env
    return cls(
../../../.pyenv/versions/3.11.4/envs/myproj/lib/python3.11/site-packages/docker/client.py:45: in __init__
    self.api = APIClient(*args, **kwargs)
../../../.pyenv/versions/3.11.4/envs/myproj/lib/python3.11/site-packages/docker/api/client.py:197: in __init__
    self._version = self._retrieve_server_version()
../../../.pyenv/versions/3.11.4/envs/myproj/lib/python3.11/site-packages/docker/api/client.py:221: in _retrieve_server_version
    raise DockerException(
E   docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

If I set DOCKER_HOST=unix:///Users/brhiggins/.docker/run/docker.sock in my shell or in Python before calling docker.from_env(), it succeeds.

I'll concede that the name from_env sort of sounds like it only considers environment variables, but I had read it as creating a client from "the current environment" more broadly, and I had expected it to behave the same as the docker CLI.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions