From 54209fc134682380a9228efc96191c0125b78696 Mon Sep 17 00:00:00 2001 From: Alessandro Corradi Date: Fri, 3 Apr 2026 13:53:37 +0200 Subject: [PATCH 1/2] fix: Manually retrieve the docker-host from the current context --- tox_docker/plugin.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tox_docker/plugin.py b/tox_docker/plugin.py index b6e38c4..e6909b5 100644 --- a/tox_docker/plugin.py +++ b/tox_docker/plugin.py @@ -40,6 +40,21 @@ class HealthCheckFailed(Exception): pass +def docker_client(): + # docker.from_env() ignores the current context configuration. + # https://github.com/docker/docker-py/issues/3146 + + ctx = docker_module.ContextAPI.get_current_context() + + base_url = os.environ.get("DOCKER_HOST", ctx.Host) + + docker = docker_module.DockerClient( + base_url=base_url, + version="auto", + ) + return docker + + def get_gateway_ip(container: Container) -> str: gateway = os.getenv("TOX_DOCKER_GATEWAY") if gateway: @@ -124,7 +139,7 @@ def docker_build_or_pull(container_config: ContainerConfig) -> None: def docker_pull(container_config: ContainerConfig) -> None: assert container_config.image - docker = docker_module.from_env(version="auto") + docker = docker_client() try: docker.images.get(str(container_config.image)) @@ -163,7 +178,7 @@ def docker_run( container_config: ContainerConfig, running_containers: RunningContainers, ) -> Container: - docker = docker_module.from_env(version="auto") + docker = docker_client() healthcheck: Dict[str, Union[List[str], int]] = {} if container_config.healthcheck_cmd: @@ -215,8 +230,6 @@ def docker_run( def docker_health_check( container_config: ContainerConfig, container: Container ) -> None: - docker = docker_module.from_env(version="auto") - if "Health" in container.attrs["State"]: log(f"health check {container_config.name!r}") while True: @@ -241,7 +254,7 @@ def docker_stop(container_config: ContainerConfig, container: Container) -> None def docker_get(container_config: ContainerConfig) -> Optional[Container]: - docker = docker_module.from_env(version="auto") + docker = docker_client() try: return docker.containers.get(container_config.runas_name) except NotFound: From f2627dd14a98b82cbb3d52fd8a6422267f777d83 Mon Sep 17 00:00:00 2001 From: Alessandro Corradi Date: Wed, 13 May 2026 14:48:12 +0200 Subject: [PATCH 2/2] fix: load TLS vars from env --- tox_docker/plugin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tox_docker/plugin.py b/tox_docker/plugin.py index e6909b5..4c271f0 100644 --- a/tox_docker/plugin.py +++ b/tox_docker/plugin.py @@ -23,6 +23,7 @@ from tox.tox_env.api import ToxEnv from tox.tox_env.errors import Fail import docker as docker_module +import docker.utils from tox_docker.config import ( ContainerConfig, @@ -46,11 +47,12 @@ def docker_client(): ctx = docker_module.ContextAPI.get_current_context() - base_url = os.environ.get("DOCKER_HOST", ctx.Host) + params = docker_module.utils.kwargs_from_env(os.environ) + params.setdefault("base_url", ctx.Host) docker = docker_module.DockerClient( - base_url=base_url, version="auto", + **params, ) return docker