Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't debug tomcat - missing JDK #55

Closed
damovsky opened this issue Nov 5, 2016 · 4 comments
Closed

can't debug tomcat - missing JDK #55

damovsky opened this issue Nov 5, 2016 · 4 comments

Comments

@damovsky
Copy link

damovsky commented Nov 5, 2016

Hi there,
I can't run tomcat in debug mode...it seems the whole image contains only JRE,but JDK is required to run tomcat in debug mode...

I can start the tomcat....

$ docker run -it tomcat:8.5.6-jre8 catalina.sh start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/lib/jvm/java-8-openjdk-amd64/jre
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

...but can't debug it

$ docker run -it tomcat:8.5.6-jre8 catalina.sh debug
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

I wonder if this is a known issue and if there is any workaround....am I the only one who uses tomcat in debug mode?

@rodrigofalco
Copy link

For anyone facing this issue.
Extending from this image, you could install openjdk.
We used run as the CMD as with start jdpa and debug the container was being killed as soon as it started.

Here, Is how we did it.

There is a setenv.sh file with this content
JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000"

And then, our dockerfile

FROM tomcat:8.5.8
MAINTAINER Rodrigo Falco <rodrigo@patagonian.it>

RUN apt-get update && \
apt-get install -y git build-essential curl wget software-properties-common

RUN echo deb http://http.debian.net/debian jessie-backports main >> /etc/apt/sources.list
RUN apt-get update && apt-get install -y openjdk-8-jdk
RUN update-alternatives --config java

ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64

COPY setenv.sh /usr/local/tomcat/bin/

EXPOSE 8000

CMD ["catalina.sh", "run"]

@bjoerndev
Copy link

Perhaps even easier:
Using "FROM tomcat:8.5.15-jre8" which itself uses "FROM openjdk:8-jre" [1], I only had to set CATALINA_OPTS to activate tomcat debugging:

ENV CATALINA_OPTS "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000"
EXPOSE 8000

[1] https://github.com/docker-library/tomcat/blob/5ac222d258dc70c77bb3a9a4fab81ea286c9abd1/8.5/jre8/Dockerfile

@tianon
Copy link
Member

tianon commented Apr 24, 2018

Nice, closing given the excellent and simple solution using CATALINA_OPTS provided above. 👍

(Which should be trivial to provide either via Dockerfile or via -e on the docker run command line.)

@tianon tianon closed this as completed Apr 24, 2018
@abrotons
Copy link

Just a note. From Java 9 onwards, JDWP address needs to be set as host:port, instead of just the port.

So if you upgrade to any -jre10 Tomcat, you will need to use:

ENV CATALINA_OPTS "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000"
EXPOSE 8000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants