Skip to content

Commit 8073874

Browse files
authored
fix(core): add TESTCONTAINERS_HOST_OVERRIDE as alternative to TC_HOST (#384)
Resolves #383 This PR aims to unify the configuration for the Testcontainer Hostvariable as it is in [Java](https://java.testcontainers.org/features/configuration/#customizing-docker-host-detection) and [Dotnet](https://dotnet.testcontainers.org/custom_configuration/) (and potentially others).
1 parent e04b7ac commit 8073874

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

core/testcontainers/core/docker_client.py

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ def host(self) -> str:
166166
# https://github.com/testcontainers/testcontainers-go/blob/dd76d1e39c654433a3d80429690d07abcec04424/docker.go#L644
167167
# if os env TC_HOST is set, use it
168168
host = os.environ.get("TC_HOST")
169+
if not host:
170+
host = os.environ.get("TESTCONTAINERS_HOST_OVERRIDE")
169171
if host:
170172
return host
171173
try:

index.rst

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ This snippet does the same, however using a specific version and the driver is s
8080

8181
Note, that the :code:`sqlalchemy` and :code:`psycopg` packages are no longer a dependency of :code:`testcontainers[postgres]` and not needed to launch the Postgres container. Your project therefore needs to declare a dependency on the used driver and db access methods you use in your code.
8282

83+
By default, Testcontainers will search for the container via the gateway IP. You can manually specify your own IP with the environment variable `TESTCONTAINERS_HOST_OVERRIDE`.
84+
8385

8486
Installation
8587
------------

0 commit comments

Comments
 (0)