r/learnjava • • 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

15 comments sorted by

View all comments

4

u/silverscrub Dec 12 '22

since the idea of a JVM should make the Java code run on any environment?

It is convenient that you can run your code on any environment, but you still want your code to run on the same environment because it's more reliable.

For example, maybe your program needs a database. You can either write in your readme how to install and configure the correct database for your program or you can include a Docker container.

Next, maybe one developer has some OS related issues when running the program locally. You could have this solved if your program was in a docker container.

It's really just at extension of a good principle to follow when coding. You want to describe a procedure as code instead of repeating yourself wherever that procedure is needed.