Skip to main content

Spicy Docker Java Images with Jolokia

·358 words·2 mins

While on the way of transforming the Jolokia integration test suite from a tedious, manual, half-a-day procedure to a full automated process I ran into and felt in love with Docker. As a byproduct a java-jolokia docker repository emerged, which can be easily used as a Java base image for enabling a Jolokia JVM agent during startup for any Java application.

These images are variants of the official java Java docker image. In order to use the Jolokia agent, a child image should call the script jolokia_opts (which is in the path). This will echo all relevant startup options that should be included as argument to the Java startup command.

Here is a simple example for creating a Tomcat 7 images which starts Jolokia along with Tomcat:

FROM jolokia/java-jolokia:7
ENV TOMCAT_VERSION 7.0.55
ENV TC apache-tomcat-${TOMCAT_VERSION}

EXPOSE 8080 8778
RUN wget http://archive.apache.org/dist/tomcat/tomcat-7/v${TOMCAT_VERSION}/bin/${TC}.tar.gz
RUN tar xzf ${TC}.tar.gz -C /opt

CMD env CATALINA_OPTS=$(jolokia_opts) /opt/${TC}/bin/catalina.sh run

(Don’t forget to use $(jolokia_opts) or with backticks, but not ${jolokia_opts})

The configuration of the Jolokia agent can be influenced with various environments variables which can be given when starting the container:

  • JOLOKIA_OFF : If set disables activation of Jolokia. By default, Jolokia is enabled.
  • JOLOKIA_CONFIG : If set uses this file (including path) as Jolokia JVM agent properties (as described in Jolokia’s reference manual. By default this is /opt/jolokia/jolokia.properties. If this file exists, it will automatically be taken as configuration
  • JOLOKIA_HOST : Host address to bind to (Default: 0.0.0.0)
  • JOLOKIA_PORT : Port to use (Default: 8778)
  • JOLOKIA_USER : User for authentication. By default authentication is switched off.
  • JOLOKIA_PASSWORD : Password for authentication. By default authentication is switched off.

So, if you start your tomcat with docker run -e JOLOKIA_OFF no agent will be started.

Currently this image is available from Docker Hub for the latest versions of Java 6,7 and 8, respectively, as they are provided by the official Docker java image.

Other base images can be easily added by using the configuration and templates from a super simple node based build system.

All appserver images from ConSol/docker-appserver (Docker Hub) are based now on this image, so Jolokia will always be by your side ;-)

Related

Using NSEnter with Boot2Docker

·452 words·3 mins
NSEnter is a nice way to connect to a running Docker container. This post presents a script to simplify the usage of nsenter together with Boot2Docker.

Docker for (Java) Developers

·184 words·1 min
Recently I gave a Meetup talk for the Docker Munich Meetup Group which explained how Docker can help developers to improve integration tests and to ship applications.

Jolokia and CORS

·1042 words·5 mins
Jolokia has configurable CORS support so that it plays nicely together with the Browser world when it comes to cross origin requests. However, Jolokia’s CORS support is not without gotchas. This post explains how Jolokias CORS supports works, what are the issues and how I plan to solve them.