Connect to Testcontainer DB with random port
Answered
Hi,
I have test suites based on Testcontainers. Whenever I run tests, a container is started for a MySQL DB. For local debugging, I like to connect to this DB to check the raw data. Testcontainer starts with random ports, so I can't simply connect, but I have to adjust the port in my stored connection with every test run.
The obvious solution to this would be setting a static port for DB containers. This is not really supported by Testcontainer though (https://github.com/testcontainers/testcontainers-java/issues/256)
So maybe someone else had that issue and found a solution for this on IDE side?
Please sign in to leave a comment.
I've taken a look at the issue and the library. Since the library manages all the docker container instances by Java code, we can do very little on the IDE side as JetBrains doesn't have any plugin/integration to this library.
Since you want to debug MySQL during development, creating the DB instance using a Docker file or Dev Container, Docker Compose is better. So you can connect your test code to the MySQL instance at a fixed port and then debug it.
Ref:
https://www.jetbrains.com/help/idea/running-a-dbms-image.html#connect_to_psql
https://github.com/IdeaUJetBrains/idea-demo-devcontainers
https://www.jetbrains.com/help/idea/docker-compose.html