Skip to content

Commit 7573fc8

Browse files
committed
chore(run-unit-tests): use CONTAINER_HOST as the user-facing env var
Linuxfabrik runs podman, not docker, so users should not have to type DOCKER_HOST when configuring the test runner against a non-default socket. CONTAINER_HOST matches the rest of the modern container ecosystem (podman --remote, buildah, skopeo) and is the natural variable for podman users. testcontainers-python only reads DOCKER_HOST internally, so the runner now accepts either CONTAINER_HOST or DOCKER_HOST as input and always populates DOCKER_HOST from whichever it finds. Already-set values are preserved for users on real docker hosts or with custom sockets.
1 parent f5cb2a4 commit 7573fc8

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

tools/run-unit-tests

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,33 @@ def is_container_test(check_plugins, plugin):
8282
def ensure_podman_env():
8383
"""Pre-flight environment setup for testcontainers under rootless podman.
8484
85-
Sets `DOCKER_HOST` to the rootless podman socket and disables the
86-
Ryuk reaper container, but only when those variables are not already
87-
set by the caller. Without this the testcontainers-python library
88-
either falls back to the docker socket (which doesn't exist on a
89-
podman-only host) or hangs trying to start a Reaper container that
90-
rootless podman cannot reach.
85+
Linuxfabrik runs podman, not docker, so the user-facing env var
86+
is `CONTAINER_HOST` (matching the Linux container ecosystem
87+
convention used by `podman --remote`, buildah, skopeo etc.).
88+
testcontainers-python only knows about `DOCKER_HOST` internally,
89+
so this helper accepts either variable as input and always
90+
populates `DOCKER_HOST` for testcontainers to consume.
91+
92+
The defaults if neither variable is set:
93+
- `unix:///run/user/$UID/podman/podman.sock` (rootless podman)
94+
- `TESTCONTAINERS_RYUK_DISABLED=true` (the Ryuk reaper hangs on
95+
rootless podman because its DinD container cannot reach back
96+
to the parent socket)
97+
98+
Already-set values are preserved so callers running on a real
99+
docker host or with a custom socket override are not affected.
91100
"""
92-
if 'DOCKER_HOST' not in os.environ:
93-
sock = f'unix:///run/user/{os.getuid()}/podman/podman.sock'
94-
os.environ['DOCKER_HOST'] = sock
95-
print(f'note: DOCKER_HOST not set, defaulting to {sock}', file=sys.stderr)
101+
container_host = os.environ.get('CONTAINER_HOST') or os.environ.get('DOCKER_HOST')
102+
if container_host is None:
103+
container_host = f'unix:///run/user/{os.getuid()}/podman/podman.sock'
104+
print(
105+
f'note: neither CONTAINER_HOST nor DOCKER_HOST is set, '
106+
f'defaulting to {container_host}',
107+
file=sys.stderr,
108+
)
109+
# testcontainers-python only reads DOCKER_HOST, so always populate it.
110+
os.environ['DOCKER_HOST'] = container_host
111+
96112
if 'TESTCONTAINERS_RYUK_DISABLED' not in os.environ:
97113
os.environ['TESTCONTAINERS_RYUK_DISABLED'] = 'true'
98114
print(

0 commit comments

Comments
 (0)