r/learnjava • u/CodeyGrammar • Dec 11 '22
Why containerize a Java program using Docker?
I'm learning Docker and the idea of having a container for a Java app seems redundant to me since the idea of a JVM should make the Java code run on any environment?
But maybe I'm missing something and see if others containerize their Java apps using Docker and why.
46
Upvotes
28
u/_Atomfinger_ Dec 11 '22
The main reason is that they're easy to deploy and mostly immutable.
It is less about the JVM and Java code and more about infrastructure, ease of scale and configuration. Sure, Java can run in any environment, but most need Java installed, and maybe you need some configuration files, you need to configure firewalls and the network, etc...
With a container, you get to replicate those parts that would otherwise need a lot of scripting or manual tweaking. Yes, Java can, in theory, run anywhere, but containers aren't really tackling that problem - at least not concerning Java.