testcontainers / testcontainers-scala

Docker containers for testing in scala

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MySQLContainer Random Port

benkio opened this issue · comments

Hi,
I write because, while trying to set up an Integration test with MySQLContainer, I noticed the port used is always random instead of the standard 3306. I attach a screenshot, in this case the random port assigned is 55040, here is the link to the code:

https://github.com/benkio/myTelegramBot/blob/ca5ee6db33455b65d3a49ebc70ab10ebbbd64d7f/botDB/src/it/scala/com/benkio/botDB/ITSpec.scala

Thanks in advance

image

I've just found a workaround by dynamically setting the DB Port via Environment Variable:
benkio/myTelegramBot@67b5758

@benkio it's not a bug, it's an intended behavior: https://www.testcontainers.org/features/networking/

From the host's perspective Testcontainers actually exposes this on a random free port. This is by design, to avoid port collisions that may arise with locally running software or in between parallel test runs.

Then I guess my solution is not actually a workaround, but rather the way to go.
I Close the issue