Skip to content

WaitForHttp requires port before container start – how to wait for mapped host port? #40

@goloroden

Description

@goloroden

I’m currently trying to use WaitForHttp in the PHP Testcontainers SDK to wait until a specific HTTP route in my container becomes available.

The challenge I’m facing is that I have to provide a port number when calling WaitForHttp. However, the actual port mapped to the host is dynamically assigned at container startup. Since I don’t know this port in advance, I run into a chicken-and-egg problem: I need to configure WaitForHttp before starting the container, but the mapped port is only available after the container has been started.

In the Go and JavaScript SDKs, this problem is solved under the hood: WaitForHttp automatically resolves the mapped host port for the given internal container port. This allows you to use dynamic port mappings (which are often preferred to avoid hardcoding ports) without running into timing issues.

In the PHP SDK, however, I couldn’t find a way to do something similar. Maybe I’m missing something? Is there a recommended approach to wait for an HTTP endpoint when the host port is assigned dynamically?

Thanks in advance – and sorry if I’ve overlooked something obvious!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions