GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Docker CLI contexts not used or supported · Issue #3146 · docker/docker-py

Docker CLI contexts not used or supported #3146

New issue
Copy link
New issue
Copy link
Closed
Closed
Docker CLI contexts not used or supported#3146
Copy link
Labels
kind/feature-request

Description

@brettdh
brettdh
opened on Jun 22, 2023
Issue body actions

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.

Reacted by brendangannkwalee, blasphemite, kronion, Martin Morset, Christian Olsen, Dan Stieglitz, Lachlan Marnham, Victor Ferreira, andreaimprovised, MAhmed and 5 more

Activity

  1. martimors commented on Sep 8, 2023

    @martimors
    martimors
    on Sep 8, 2023
    More actions

    Facing the exact issue.

    NAME       DESCRIPTION                               DOCKER ENDPOINT                                           ERROR
    colima *   colima                                    unix:///Users/dingobar/.colima/default/docker.sock
    default    Current DOCKER_HOST based configuration   unix:///var/run/docker.sock
    

    In this scenario I'd expect docker-py to use the Colima context.

    My awful workaround is

    echo 'export DOCKER_HOST="unix:///Users/dingobar/.colima/default/docker.sock"' >> ~/.zshrc
    Reacted by Christian Olsen, Salomon Popp, Michael Scrivo and Jerry Yang
  2. milas
    changed the title [-]docker.from_env() ignores active context[/-] [+]Docker CLI contexts not used or supported[/+] on Nov 21, 2023
  3. milas
    added
    kind/feature-request
    on Nov 21, 2023
  4. milas
    pinned this issue on Nov 21, 2023
  5. AstraLuma commented on Nov 30, 2023

    @AstraLuma
    AstraLuma
    on Nov 30, 2023
    More actions

    I'm doing this:

    def get_client(use: str | None = None) -> docker.DockerClient:
        """
        Get a docker client for the given docker context
        """
        context = docker.ContextAPI.get_context(use)
        if context is None:
            raise ContextNotExistError(f"Docker context {use!r} not found")
        return docker.DockerClient(
            base_url=context.endpoints["docker"]["Host"],
            tls=context.TLSConfig
        )
    
  6. AstraLuma commented on Nov 30, 2023

    @AstraLuma
    AstraLuma
    on Nov 30, 2023
    More actions

    You might be running into #3190?

  7. martimors commented on Dec 1, 2023

    @martimors
    martimors
    on Dec 1, 2023
    More actions

    I don't want to write code that selects a specific context, docker-py should know to use the current context.

  8. Khushiyant commented on Jan 4, 2024

    @Khushiyant
    Khushiyant
    on Jan 4, 2024
    Contributor
    More actions

    Hey, anyone working on this issue? I have some idea for this issue.

  9. David234-star commented on Jun 22, 2024

    @David234-star
    David234-star
    on Jun 22, 2024
    More actions

    The Docker CLI context not used or supported error message means that the Docker CLI cannot find a context that matches the specified name. This can happen for a few reasons:

    • The context does not exist.
    • The context is not accessible to the Docker CLI.
    • The context is not supported by the Docker CLI.

    To resolve this error, you can try the following:
    Check the name of the context and make sure that it is correct.
    Make sure that the context is accessible to the Docker CLI. You can do this by running the docker context ls command. This will list all of the available contexts.
    Make sure that the context is supported by the Docker CLI. You can do this by running the docker info command. This will show you the version of the Docker CLI that you are using.
    If you are still having problems, you can contact Docker support for assistance.

    is this correct? guys, I am new to this docker world, so please let me know. everything is AI-generated except me, help me to explore and tackle the open source multiverse

    Reacted by Martin Morset, Jamie Bliss, An Guoli, Khushiyant, Stefan Pejcic, Mark Dickinson, Nicholas de Paola , Chirag Jain and Felix Fontein
  10. stefanpejcic commented on Sep 19, 2024

    @stefanpejcic
    stefanpejcic
    on Sep 19, 2024
    More actions

    I stumbled here searching hot to specify context to docker.from_env()

    Workaround I used is to specify context name, if provided, run command and check the endpoint for that context:

    def get_context_endpoint(context_name):
        try:
            result = subprocess.run(['docker', 'context', 'ls'],
                                    capture_output=True, text=True, check=True)
            
            for line in result.stdout.splitlines()[1:]:
                parts = line.split()
                name = parts[0]
                endpoint = ' '.join(parts[1:])
                
                if name == context_name:
                    return endpoint
        except subprocess.CalledProcessError:
            return None
    

    sepcify that endpoint:

            if docker_context == 'default':
                client = docker.from_env()
            else:
                endpoint = get_context_endpoint(docker_context)
                client = docker.DockerClient(base_url=endpoint)
    
  11. ale-cci
    added 3 commits that reference this issue on Feb 19, 2026

    fix: Use host provided by default context if base_url is not provided.

    84e283d

    fix: Use Host provided by default context if no host is provided.

    b92cee5

    fix: Use Host provided by default context if no host is provided.

    331e469
  12. ale-cci
    added 4 commits that reference this issue on Apr 2, 2026

    fix: Use Host provided by default context if no host is provided.

    1403d54

    fix: Use Host provided by default context if no host is provided.

    0ce053c

    fix: Use Host provided by default context if no host is provided.

    a8ae17b

    fix: Use Host provided by default context if no host is provided.

    954b953
  13. TeaDrinkingProgrammer commented on Jul 1, 2026

    @TeaDrinkingProgrammer
    TeaDrinkingProgrammer
    on Jul 1, 2026
    More actions

    Can confirm the bug still exists and it is fixed by creating a config.json file (touch ~/.docker/config.json). Could this be reclassed as a bug? This breaks workflows on new systems without config.json

  14. vvoland
    closed this as completedon Jul 9, 2026
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

    kind/feature-request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.