Container: Developing an Application - Remote Debugging

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. This was setup for a tomcat application using the following instructions. 

Remote Debugging

The following text was added to the end of the Dockerfile and there are three sections where a commented line should be fully formatted as code:

# Port 5009 s used by the eclipse remote debugger and jvm.  This port may be different for your application.

ENV JPDA_ADDRESS="5009"
ENV JPDA_TRANSPORT="dt_socket"
catalina.sh jpda run

Additionally, some applications may require the container to expose the debugging/profiler port. If the configuration above fails, try adding the following line:

# Port 5009 is used be the eclipse remote debugger and the jvm. This port may be different for your application.

EXPOSE 5009

This tells tomcat to listen on #Port 5009 for connects using jpda, the debugging protocol. More specific instructions are available per the second example here.

Once the application is listening on that port, the developer can forward local traffic to that remote port using the following command:

# Port 5009 is used be the eclipse remote debugger and the jvm. This port may be different for your application.

oc port-forward {pod-name} 5009

This will forward all traffic from localhost:5009 to the pod at #Port 5009.

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.

Within the IDE, the developer will debug by listening on localhost and the port specified above. 

In this case: localhost:5009

If an application is running its own local database pod it is likely there isn't a open route straight to the database which makes it hard to access for debugging. Port Forwarding can easily make the database port temporarily available.

Last Updated: 
Tuesday, September 11, 2018