Skip to content

Commit 42bb736

Browse files
committed
feat: fallback to default socket address when docker.from_env() fails
1 parent 632e5f4 commit 42bb736

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

core/testcontainers/core/config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@ def get_docker_socket() -> str:
3333
if socket_path := environ.get("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE"):
3434
return socket_path
3535

36-
client = docker.from_env()
36+
default_socket_address: str = "/var/run/docker.sock"
37+
try:
38+
client = docker.from_env()
39+
except docker.errors.DockerException:
40+
return default_socket_address
3741
try:
3842
socket_path = client.api.get_adapter(client.api.base_url).socket_path
3943
# return the normalized path as string
4044
return str(Path(socket_path).absolute())
4145
except AttributeError:
42-
return "/var/run/docker.sock"
46+
return default_socket_address
4347

4448

4549
MAX_TRIES = int(environ.get("TC_MAX_TRIES", 120))

0 commit comments

Comments
 (0)