Remote Debugging for XWiki in Docker Using JVM Options
Explanation
Remote debugging allows you to connect an IDE debugger to the Java process running XWiki inside the Docker container. This can be useful when developing extensions, troubleshooting issues, or analyzing runtime behavior. To perform remote debugging on an XWiki instance started using a Docker container you need to:
- expose the debug port (using the -p option when executing docker run),
- configure Tomcat to start Java in debug mode: set the JAVA_OPTS environment variable and start the container. Then, start the container. For example:
docker run --net=xwiki-nw --name xwiki -p 8080:8080 -v xwiki:/usr/local/xwiki -e DB_USER=xwiki -e DB_PASSWORD=xwiki -e DB_DATABASE=xwiki -e DB_HOST=mysql-xwiki -e JAVA_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:5005" -p 5005:5005 xwiki
Don't forget to replace xwiki-nw with the name of your Docker network, the vales of the environment variables.
When debug options are passed through the JAVA_OPTS environment variable, Tomcat starts the JVM. Once the debugger is attached, you can inspect variables, set breakpoints, step through the code, and analyze runtime behavior directly on the running XWiki instance.
If the JVM is started with suspend=y, startup is paused until a debugger connects. If suspend=n is used, XWiki starts normally and the debugger can be attached later.