Overview
Developers may wish to debug a running instance of an application. Once done, developers can set breakpoints to verify the state of variables in run-time.
OpenShift Documentation on Port Forwarding
Enabling Port Forwarding
Once the application has been configured to listen on the debugging port, developers can forward local traffic to container using the following command:
oc port-forward {pod-name} 5009
Where pod-name is the name of the OpenShift pod you wish to debug. This will forward all traffic from localhost:5009 to the pod at port 5009. Within the IDE, the developer will debug by listening on localhost and the port specified above.
Note: This port must not conflict with any ports defined within the service and deployment configuration. The app must not be listening on that port in any other way.
Port forwarding is an effective means to troubleshoot pods without ports that have been exposed as routes, such as database pods. Port forwarding makes ports temporarily available, and only to the client who has setup the forwarding session.
An Example of Enabling Remote Debugging
In this example, we are enabling port 5009, as this is used by the Eclipse remote debugger and jvm. This port may be different for your application. The following text was added to the end of the Dockerfile:
ENV JPDA_ADDRESS="5009"
ENV JPDA_TRANSPORT="dt_socket"
catalina.sh jpda run