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

2

u/ignotos Dec 12 '22

Another benefit is that it's simply very well supported with tooling. "Run this docker image on this server" is something which works with minimal fuss and configuration.

So you can run a simple command on your machine saying "package up my project into a docker image, and tag it as my-app version 1.0", and then on your cloud provider you can say "I want to spin up servers running 10 copies of my-app version 1.0".

Then, later on, you can make some changes to your code, package it up as version 1.1, and have all of your servers updated with a couple of clicks in the web console or command-line tool.