From 6b330256799b5cca241f706805267949a29b893c Mon Sep 17 00:00:00 2001 From: Jan Meiswinkel Date: Mon, 2 Oct 2023 16:10:08 +0200 Subject: [PATCH 1/2] feat: add alternative to TC_HOST as in Java / .NET --- core/testcontainers/core/docker_client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/testcontainers/core/docker_client.py b/core/testcontainers/core/docker_client.py index 9ff6170e..e43dddb4 100644 --- a/core/testcontainers/core/docker_client.py +++ b/core/testcontainers/core/docker_client.py @@ -166,6 +166,8 @@ def host(self) -> str: # https://github.com/testcontainers/testcontainers-go/blob/dd76d1e39c654433a3d80429690d07abcec04424/docker.go#L644 # if os env TC_HOST is set, use it host = os.environ.get("TC_HOST") + if not host: + host = os.environ.get("TESTCONTAINERS_HOST_OVERRIDE") if host: return host try: From 52a26bce88cbd193b280b48bc5e9a91ee583ea88 Mon Sep 17 00:00:00 2001 From: Jan Meiswinkel Date: Mon, 2 Oct 2023 16:16:42 +0200 Subject: [PATCH 2/2] Update README.rst --- index.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.rst b/index.rst index 4f3dad80..0f9cd5a3 100644 --- a/index.rst +++ b/index.rst @@ -80,6 +80,8 @@ This snippet does the same, however using a specific version and the driver is s 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. +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`. + Installation ------------