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
3
u/AsleepThought Dec 12 '22
Because Java does not run on ANY platform unless you install the JVM.
Then you need to ask "which version of the JVM should be installed on the system?". Unfortunately for you (the system admin) there are now a plethora of legacy apps dependent on old Java, and a plethora of new apps dependent on new Java.
And that is not counting other third-party software that also needs its own Java management.
As you can see from this, Java being able to "run in any environment" stopped being a real feature in the late 90's. Its simply not true, and arguably never was true.
Java's dependence on a JVM to run your programs makes it as limiting for real-world deployments as any other interpreter-bound programming language. Sad.
So make sure to Dockerize your Java app, or its likely no one will ever be able to actually use it unless you really put in the work to bundle Java installation and management methods into your app's installer.