testcontainers-rs icon indicating copy to clipboard operation
testcontainers-rs copied to clipboard

[RFC] An API design that statically couples available ports to the started image

Open thomaseizinger opened this issue 5 years ago • 0 comments

Currently, users can request a mapped host port from a container through Container#get_host_port.

This API allows users to pass whichever port the want and the function will simply return an Option if the port was not mapped.

It would be interesting to explore an API where implementations of Image could somehow statically specify, which particular ports will be exposed. They should "know" that because we know which docker image we will be starting.

The advantage I am trying to gain from that is increased discoverability:

If I am starting a postgres container through testcontainers, I don't want to need to know that postgres exposes port 5432. Instead, it would be nice if I could discover that through intelli-sense on the container that I just started.

Design suggestions are highly welcome!

thomaseizinger avatar Oct 21 '20 00:10 thomaseizinger