无法在Docker容器内使用IntelliJ调试WebSphere应用服务器。

huangapple go评论71阅读模式
英文:

Cannot debug Websphere Application Server inside of a Docker container using IntelliJ

问题

我正在尝试将一个 WebSphere 应用服务器(WAS)迁移到容器中,并且继续具备调试能力。这是一个传统的 WAS 版本 8.5.5.17。我尝试了多种方法,但是我无法成功地在 IntelliJ 中附加远程调试器。在查看 server.xml 时,WAS 被设置为 debugMode,但是没有监听端口。与调试相关的 JVM 属性设置如下:

debugMode="true" debugArgs="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7777" genericJvmArguments=""

Dockerfile:

FROM ibmcom/websphere-traditional:8.5.5.17

COPY db /work/config/db
COPY MQ /work/config/MQ
COPY earear /work/config/ear.ear
COPY custom_jvm_properties.txt /work/config/custom_jvm_properties.txt
COPY file.properties /work/config/file.properties
COPY Sscript.py /work/config/Script.py
COPY jars/work/config/jars
RUN mkdir -p /work/config/Folder

RUN /work/configure.sh

EXPOSE 80 9080 9448 9443 9060 9043 7777

当我使用上述文件构建镜像时,容器会构建,并且应用程序可以运行。取消注释 #ENV 行会导致镜像构建成功,但是运行容器会出现以下错误:

ERROR: transport error 202: bind failed: Address already in use
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:762]

我的 docker run 命令如下:

docker run -p 80:80 -p 9080:9080 -p 9448:9448 -p 9443:9443 -p 9060:9060 -p 9043:9043 -p 7777:7777 -v C:\volume:/volume --name ContainerName image

尝试将 JAVA_TOOL_OPTIONS 作为环境变量传递也不起作用。目前,我可以在调试模式下启动服务器,但是没有任何监听端口可供调试器连接,或者由于上述错误的原因,服务器启动失败,无法使用监听端口。

英文:

I am trying to move a WAS into a container, and continue to have the ability to debug it. It is a traditional WAS version 8.5.5.17. I've tried multiple things, but I cannot successfully attach a remote debugger using IntelliJ. The WAS is set to debugMode when looking through the server.xml, but there is no listening port. The JVM properties related to debugging are set as follows:

debugMode="true" debugArgs="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7777" genericJvmArguments=""

Dockerfile:

FROM ibmcom/websphere-traditional:8.5.5.17

COPY db /work/config/db
COPY MQ /work/config/MQ
COPY earear /work/config/ear.ear
COPY custom_jvm_properties.txt /work/config/custom_jvm_properties.txt
COPY file.properties /work/config/file.properties
COPY Sscript.py /work/config/Script.py
COPY jars/work/config/jars
RUN mkdir -p /work/config/Folder

RUN /work/configure.sh

#ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7777
EXPOSE 80 9080 9448 9443 9060 9043 7777

When I build the image using the above file, the container builds and the application can be ran. Uncommenting out the #ENV line results in the image being built, but running the container results in the following error:

ERROR: transport error 202: bind failed: Address already in use
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:762]

My docker run command is as follows:

docker run -p 80:80 -p 9080:9080 -p 9448:9448 -p 9443:9443 -p 9060:9060 -p 9043:9043 -p 7777:7777 -v C:\volume:/volume --name ContainerName image

Trying to pass the JAVA_TOOL_OPTIONS as an environmental variable does not work either. At this point I can start the server in debug mode, but not have any listening ports to attach a debugger to, or the server fails to start with listening ports because of the above error.

答案1

得分: 1

替代将调试选项提供给您的方法是使用以下方式:

#ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7777

我认为推荐的做法是将这些调试选项放在一个属性文件(debug.props)中:

debugArgs="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7777"

然后将其复制到您的 Docker 镜像中:

COPY --chown=was:root debug.props /work/config/debug.props

最后,应用此配置:

RUN work/applyConfig.sh /work/config/debug.props

在此处查看示例项目:https://github.com/WASdev/ci.docker.websphere-traditional/tree/10367b51ccbf489cd6e1655769b968e9d9bfca13/samples/batch-compute-grid

英文:

Instead of providing your debug options using

#ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7777

I believe the recommended procedure would be to put these debug options within a properties file (debug.props) under:

debugArgs="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7777"

Then copy to your docker image:

COPY --chown=was:root debug.props /work/config/debug.props

Finally, apply this config:

RUN work/applyConfig.sh /work/config/debug.props

See sample project here: https://github.com/WASdev/ci.docker.websphere-traditional/tree/10367b51ccbf489cd6e1655769b968e9d9bfca13/samples/batch-compute-grid

答案2

得分: 0

成功尝试了一下IntelliJ,通过操作后解决了。

我试着按照这篇指南:https://blog.jetbrains.com/idea/2019/04/debug-your-java-applications-in-docker-using-intellij-idea/

不过,还需要进行一些额外的设置。我必须配置WebSphere镜像进行构建,并设置始终以调试模式启动(这可能会在后面造成一些减速,但这是一个允许我进行调试的权宜之计,可以在重新构建镜像时移除)。在此之后,只有在服务器完全启动后才能附加远程调试器。虽然没有提示服务器有一个可用的监听端口,但实际上是有的。使用“在调试前启动Docker”选项会导致附加失败。感谢提供的帮助!

英文:

Managed to figure it out after playing around with IntelliJ.

I was trying to follow this guide https://blog.jetbrains.com/idea/2019/04/debug-your-java-applications-in-docker-using-intellij-idea/

However, it took some additional set-up. I had to configure the websphere image to build and set it to always start in debug mode (May cause slow-downs further along, but this was a workaround that allows me to debug and can be removed when rebuilding the image). After this, I could only attach the remote debugger once the server was completely started. There was no prompt that the server had an available port to listen to, but it did. Using the "Launch docker before debug" option would result in a failure to attach. Thanks for the help!

huangapple
  • 本文由 发表于 2020年9月22日 04:48:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/63999792.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定