Skip to content

WIP: Host ip fix #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions testcontainers/core/container.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from deprecation import deprecated
from docker.models.containers import Container

Expand Down Expand Up @@ -82,6 +84,10 @@ def get_container_host_ip(self) -> str:
if not host:
return "localhost"

host = os.environ.get('TC_HOST')
if host:
return host

# check testcontainers itself runs inside docker container
if inside_container():
# If newly spawned container's gateway IP address from the docker
Expand Down
4 changes: 4 additions & 0 deletions testcontainers/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@

from testcontainers.core.container import DockerContainer
from testcontainers.core.waiting_utils import wait_container_is_ready
from testcontainers.core.utils import setup_logger
from deprecation import deprecated

logger = setup_logger(__name__)


class DbContainer(DockerContainer):
def __init__(self, image, **kwargs):
Expand All @@ -41,6 +44,7 @@ def _create_connection_url(self, dialect, username, password,
)
if db_name:
url += '/' + db_name
logger.info("Connection url: %s", url)
return url

def start(self):
Expand Down