Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java JVM on Docker/CoreOS

I'm learning CoreOS/Docker and am trying to wrap my mind around a few things.

With Java infrastructure, is it possible to use the JVM in it's own container and have other Java apps/services use this JVM container? If not, I'm assuming the JVM would have to be bundled in each container, so essentially you have to pull the Java dockerfile and merge my Java services; essentially creating a Linux Machine + Java + Service container running on top of the CoreOS machine.

The only other thought I had was it might be possible to run the JVM on CoreOS itself, but it seems like this isn't possible.

like image 763
AmericanKryptonite Avatar asked Dec 03 '14 19:12

AmericanKryptonite


People also ask

Does Docker contain JVM?

No, docker does not have it's own JVM. In fact, Docker and Java should be considered two entirely separate technologies. There's no requirement for a Docker container to have any java implementation installed.

Does Docker support Java?

Fortunately — yes, there is! The new Java version (10 and above) docker support is already built-in.

What is Openjdk slim?

openjdk:<version>-slimIt only contains the minimal packages needed to run Java. Unless you are working in an environment where only the openjdk image will be deployed and you have space constraints, we highly recommend using the default image of this repository.

What is :+ UseContainerSupport?

-XX:+UseContainerSupport is used to allocate a larger fraction of memory. To prevent the JVM adjusting the maximum heap size when running in a container, set -XX:-UseContainerSupport .


2 Answers

It is actually possible to just untar Orcale Java in /opt, but that's just a kind of last resort. The Oracle binaries of JRE and JDK don't require any system libraries, so it's pretty easy anywhere.

I have written some pretty small JRE and JDK images, with which I was able to run Elasticsearch and other major open-source applications. I also wrote some containers that allow me to compile jars on CoreOS (errordeveloper/mvn, errordeveloper/sbt & errordeveloper/lein).

As @ISanych pointed out, running multiple Java containers will not impact disk usage, it's pretty much equivalent to running multiple JVMs on the host. If you find that running multiple JVMs is not quite your cuppa tea, then the answer is really that JVM wouldn't have to be as complex as it is if containers existed before it. However, Java in container is still pretty good, as you can have one classpath that would be fixed forever and you won't get into dependency hell. Perhaps instead of building uberjars (which is what I mostly do, despite that they are known to be not exactly perfect, but I am lazy) one could instead bundle jars in tarball and then use ADD jars.tar /app/lib/ in their Dockerfile.

like image 55
errordeveloper Avatar answered Oct 23 '22 15:10

errordeveloper


Applications that run on JVM will have to have JVM installed in the container. So if you want to split application components into separate containers, each of these containers need to have JVM. On a side note, containers can talk to each other via a process called container linking

like image 1
Jerome Anthony Avatar answered Oct 23 '22 15:10

Jerome Anthony