Java JVM on Docker/CoreOS
Asked Answered
P

3

5

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.

Plenary answered 3/12, 2014 at 19:31 Comment(0)
C
4

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.

Collectivity answered 5/12, 2014 at 15:51 Comment(1)
I have also just put out a blog post with few more details on this: weaveblog.com/2014/12/09/…Collectivity
D
1

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

Deerdre answered 4/12, 2014 at 0:47 Comment(0)
M
0

Best practice will be to create image with jvm and then other images based on jvm image (from jvm in Dockerfile). Even if you will create many different images they would not waste much space as docker is using layered file system and all containers will use the same single copy of jvm image. Yes each jvm will be separate process eating own memory - but isolated environments that is what docker is used for.

Mugwump answered 4/12, 2014 at 0:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.