Connect to database instance running inside a Java testcontainer using IntelliJ IDEA
Testcontainers library (Java) is generally used along with Junit test cases to spawn a test environment within a docker container. IntelliJ IDEA provides an option to run these test cases from within the IDE.
Databases spwaned using testcontainers when run from within the IDE can become inaccessible from outside the IDE. In order to connect to such databases you can uses the database tool that comes with IDEA ultimate version.
Steps:
Add a debug point in the code such that the testcontainer has been brought up at this point.
Run the test program using debug mode and wait till it stops on the break point.
Click on the database tool.
Select your database type.
Enter your credentials. Test your connection and save credentials.
Run query.