Skip to content
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

Bug: tc.host support issue - failing to connect to dockerd if tc.host is present #494

Open
alexanderankin opened this issue Mar 24, 2024 · 1 comment

Comments

@alexanderankin
Copy link
Collaborator

Describe the bug

when we added #388 it reads stale data (or even in an older format?) and fails to connect to docker, preferring to connect to a tc desktop that may not be running anymore.

this library should validate the format before consuming the value, and potentially also check for a healthy server running on that port.

To Reproduce

Add/comment/uncomment the below line in ~/.testcontainers.properties

tc.host=tcp\://127.0.0.1\:42319

Runtime environment

n/a

@alexanderankin alexanderankin changed the title Bug: Bug: tc.host support issue - failing to connect to dockerd if tc.host is present Mar 24, 2024
@alexanderankin
Copy link
Collaborator Author

#524 related kind of, was thinking of consolidating PRs:

def get_docker_host() -> Optional[str]:
    tc_host = read_tc_properties().get("tc.host")

    # make sure if we have a value, that it is still valid (we can talk to it via tcp)
    if tc_host:
        try:
            with socket(AF_INET, SOCK_STREAM) as sock:
                sock.settimeout(1)
                sock.connect(*(urllib.parse.urlparse(tc_host).netloc.rsplit(":", 1)))
        except ConnectionRefusedError:
            tc_host = None

    return tc_host or os.getenv("DOCKER_HOST")

alexanderankin added a commit that referenced this issue Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant