Mostly package will deliver in container image, and for testing / debugging on dockerfile, we will run it locally. However, it cannot be debug easily. So we need to alter configuration to enable it.
In this demo, we will show how to enable debug in IntelliJ.
Prerequisites
-
Applications below should be installed latest version and configuretd properly in local computer.
-
IntelliJ;
-
Docker;
-
-
Plugin Docker should be installed in IntelliJ properly;
-
Project related Dockerfile should be placed properly;
Steps
-
Create Dockerfile debug configuration.
In IntelliJ, select Run > Edit Configuration > click “+” and select Dockerfile under Item Docker. -
Configure Dockerfile configuration.
In new dockerfile configuration, change properties as below.
Dockerfile: dockerfile
Context folder: build\libs (Jar file path)
Command: java -jar <<jar path configurated in dockerfile>> (Example: java -jar /opt/test-service.jar)
Bind port: 5050:5050 <<jar port to be used>>(Example: 5050:5050 8080:8080) -
Enable deploy built jar from current source code.
In Before launch, click “+” and select Run Gradle task, in Gradle project select project, input build in Tasks. To speed-up build process, it can add -x test in Arguments.
Then click OK to save settings. -
Add Remote debug configuration.
In Run / Debug configuration, click “+” and select Remote JVM Debug. -
Configure remote debug settings.
In Use module classpath, select project main class. -
Enable run docker before start debug.
In Before launch menu, click “+”, select Launch docker before debug. select docker configuration which done in previous step and input -p 5005:5005 in custom options.
then click OK to apply settings. -
Test debug can be run or not.
Add break points in code, and select remote debug configure. Then run it in debug mode.
After container connected and executed. Call related API to check breakpoint can be trigger or not.
Leave a Reply