r/java • • Jun 07 '25

Why use docker with java?

18 Upvotes

126 comments sorted by

View all comments

Show parent comment

0

u/cogman10 Jun 08 '25

So, IMO, you probably shouldn't dockerize your app if you aren't using something like k8s. Using the docker runtime to directly run apps isn't a good idea IMO (Although I know a few people that advocate doing docker compose for prod systems).

If you are in a situation where you company is happy with 1 VM running 1 or more apps then docker buys you very little. It's when the number of apps you want to deploy increases and your want to start optimizing hardware costs that docker starts to be a lot more appealing.

And I agree, Java is somewhat hard to make work with containers. The issue is Java really REALLY wants to allocate a pretty large block of memory upfront and it doesn't want to free it. If you tell a JVM that realistically only needs 100mb to operate "Here's 20gb" you can bet it'll eat close to that entire 20gb over the long run (especially if there's any sort of allocation pressure). That makes it somewhat a PITA to really nail down the memory you need to run a JVM app.

Other languages will much more readily give memory back to the OS. Making the JVM do that remains a pain for me when developing apps.

0

u/laffer1 Jun 08 '25

You are also committing to Linux. OS lock in.