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

Can we let Docker choose a port?

Open rotivleal opened this issue 1 year ago • 0 comments

I need to run tests in parallel.

Each test will spawn its own Kafka.

Each test will have a producer/consumer, connected to that Kafka.

Kafka therefore needs to expose a port, and it needs to be mapped to a host port. Problem is, since tests will run in parallel, I can't reuse the same port.

Docker allows you to generate a random host port by just running -p <internal>.

But the API forces me to specify the host port: https://github.com/testcontainers/testcontainers-rs/blob/71bbdec013c1b19e5507217d52c612c71d9473f5/testcontainers/src/clients/cli.rs#L193-L198

This same problem had been discussed in #285 which leads me to believe that somewhere in the API I'm allowed to do that... otherwise, why was it removed...?

Thanks.

rotivleal avatar Mar 19 '24 11:03 rotivleal