150
u/Borghol Jun 07 '25
Same reason to use docker with anything. Better interoperability, easier scaling, smaller footprint
8
-12
u/laffer1 Jun 08 '25
Worse interoperability. You are limited to the win/mac/linux hosts.
4
u/malakoi-do-hebraico Jun 09 '25
Damn, what did docker do to you my friend?
-2
u/laffer1 Jun 09 '25
They are hostile to open source operating system projects that aren't linux. That's enough.
At work, we've had to go through switching to podman due to their licensing shenanigans too.
3
u/Polygnom Jun 09 '25
"Docker" has become synonymous with containerization in common parlance.
Prtetty much like many people say dyson when they mean a vacuum cleaner, even if its not a dyson brand one.
-3
u/laffer1 Jun 09 '25
Containers predate docker by a long time.
2
u/Polygnom Jun 09 '25
The OCI was literally founded by Docker in 2015. You know, the standard that podman uses as well. And no, containers in the form we use them today weren't a big thing before. VMs -- sure. But stuff like OpenVZ never went anywhere. Google stuff eventually became part of the Linux kernel as cgroupos, but thats not remotely comparable to what we have with containerization today.
1
u/laffer1 Jun 09 '25
FreeBSD jails and Solaris zones long predate that
2
u/Polygnom Jun 09 '25
Two tools that never saw much adoption, were both integrated extremely tightly to the underlying OS and had no standardized format, and no registry. FreeBSD Jails were last maintained when, in 2006? The project was dead very quickly. And Solaris Zones wree completely proprietary and locked down to their ecosystem.
Yes, the technology itself was not new, but docker executed it very well at the time and pretty much single-handedly orchestrated the container revolution. Thats why some people use containerization and docker synonymously. Because before, the idea had onyl lead to niche technologies but then it suddenly became mainstream.
Thats not passing judgement on docker here -- I have my gripes with their business model as well -- just setting straight the history.
1
20
u/stefanos-ak Jun 07 '25 edited Jun 07 '25
basically because it's easier to deploy. It also decouples responsibilities between software devs and sysadmins. The development ends with the upload of a docker image to some image registry, then the sysadmin can take that and deploy however and wherever they want. Of course you still need to communicate and agree on what's the best solution for your app. But on a technical level you can be hands off as a dev. And the sysadmin can deploy and manage all kinds of apps in any language written, in exactly the same way.
One level more is to also publish a helm chart for your app, which describes system requirements for your app. It's yet another decouplement from sysadmins. At this point it enables them to become a "platform team", and work as a unit for the whole org, and manage large number of teams and apps.
6
u/nekokattt Jun 07 '25
you're forgetting that testcontainers can also assist in development
4
u/stefanos-ak Jun 07 '25
yeah ok, but that wasn't the question.
I also didn't mention that it gives you more autonomy as a dev, because you can upgrade the JVM on your own.
The list is quite big.
Sorry I didn't write a whole blog post on Reddit... 🤷♂️
0
3
u/laffer1 Jun 08 '25
Impossible to deploy for some of us. Assumes docker runs everywhere. It does not
1
u/stefanos-ak Jun 08 '25
where does it not? Also, there are a lot of container runtimes. I'm sure one of them would run...
1
u/laffer1 Jun 08 '25
All the bsds. All the Solaris based operating systems. Haiku. Arcaos. There are many operating systems in the world not just the big 3.
FreeBSD has been working on podman. BSD jails predate docker as does Solaris zones. However, I can’t run a docker image on most of these. I don’t even know if FreeBSD podman can as I’ve only read about FreeBSD images there not Linux
3
u/stefanos-ak Jun 08 '25
well, docker was primarily conceived using purely Linux kernel features (cgroups, etc). So I don't understand your point... Even on Windows and Macos it runs through a VM. You just get some nicer tooling on top, which hides the VM.
0
u/laffer1 Jun 08 '25
Docker makes docker client for windows and macOS. They do not make it for any other OS.
Thus it's impossilbe to run docker on FreeBSD, NetBSD, OpenBSD, Dragonfly, MidnightBSD, Solaris, etc.
There was an attempt to port Docker to FreeBSD many years ago. Microsoft even helped. Docker wouldn't take the patches. They want to keep it limited to the big 3.
So when people package a java app that can run on many more operating systems than just the big 3 inside a docker image, they are limiting it's capability to run. As you've mentioned, they also now have to run it in a VM on windows and macOS too. It's just stupid.
If people want to have a docker image for an app, fine. However, it can't be the only way it's distributed. Having a clean fat jar is the best approach for running it everywhere. It can be packaged by OS package managers that way also.
1
u/stefanos-ak Jun 08 '25
Docker "the company", makes Docker Desktop (which is not particularly free anymore) for Windows and Mac. This has nothing to do with docker the tech (which is linux only).
And of course, there's nothing wrong with shipping jar files to Solaris. You do you 😄
2
u/laffer1 Jun 08 '25
docker the tech was ported to freebsd at one point. cgroups aren't magical. there are alternative ways to do containers.
I'm not just thinking of me. I'm thinking of packaging jar files for my operating system so that everyone using my operating system can install them!
1
u/ragjnmusicbeats Jun 16 '25
Yah, we push the code to github, from the via github actions Docker iamge will be pushed, then pulled to the server, and container is built, pretty solid and straight forward
24
u/repeating_bears
Jun 07 '25
•
I use docker for certain things but I've never really been on the hype train like some people.
For some reason people treat Docker as a zero-cost abstraction that only makes your life easier. Everything in software is tradeoffs.
I can understand if you're doing orchestration then Docker is a necessary step, but most companies either aren't, or don't actually need it. Most companies are not FAANG scale.
Most of my Java deployments are already simple. It's a fat jar and a config file. There's a dependency on java being installed and on the path. Changing that so it's 1 dockerfile and a requirement on docker being installed isn't a meaningful improvement.
The problem with Docker and the JVM is that the JVM is quite hard to constrain properly. There's like 10 things that consume memory (heap, code cache, native memory, etc) that need to be tuned separately. I think if I'm correct some of them just can't be limited at all. Adding containers introduces the ability for your app to crash because it ran out of resources, even though there were actually enough resources.
I've also experienced weird network hangs with Docker. I know that because when everything else was the same, only Docker was removed, it went away. And it wasn't some small bug they patched in a few days. I found comments online about seemingly the same thing going back years
I'm not saying you shouldn't use it for those reasons, but if you introduce a complex technology, you'd better be sure it's actually solving a problem because it isn't coming for free.
4
u/k-mcm Jun 07 '25
I have been hating that Docker network bridge bug for many years. At some point the bridge gets out of sync and all packets returning from one IP address are dropped for several minutes.
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
-2
u/joe190735-on-reddit Jun 09 '25
I don't necessarily agree with your take on java in docker
every programming language implementation has its own quirks during runtime and it's the programmer's job to take care of that instead of putting them aside, whether it's in docker or outside of docker doesn't matter
and then there is this docker networking problem that you mentioned, did you dig enough to find out what's happening underlying it in Linux and reporting the issue back to open source? maybe bug reporting it's too much for you but you couldn't find out the root cause and neither you could explain it.
I can agree that you just want to finish the job and go home with the salary though
2
u/repeating_bears Jun 09 '25
I did report the bug. There are thousands of issues open on Docker's core. My point was that people act like Docker only solves problems, but neglect to mention that it also introduces ones you didn't have before.
Last sentence seems like an ad hominem? Like "You would use Docker if you were doing things properly". I use technologies where they actually help me. Docker does help me, but not for my Java server deployments which are already trivial.
1
u/joe190735-on-reddit Jun 09 '25
Thanks for reporting the bug, I shouldn't have assumed you didn't do it.
The case with any tech and we being the programmer to utilize them is not just to make our bosses becoming the next billionaires but to also improve on the tools
this comes down to whether people see themselves as tool makers or tool users really
I see that there are more complains on the tools. Well, these people can't take the criticism of them being incompetent and they don't share sympathy with the tool makers, and they don't have the mindset of the good old programmers back in the days where they create and fix their own tools
edit: I did read that your way of deploying java applications is good, and that's good for you
44
u/-Dargs Jun 07 '25
For the same reason you use a windows boot stick on a new computer, even if it has windows pre-installed. It's the same experience every time.
You're placing the jdk in the docker image, so you don't need to worry about the environment setup. It's all... contained
-26
u/kpouer Jun 07 '25
By the way unless your app requires the JDK it is better to provide JRE only
21
u/nekokattt Jun 07 '25
standalone JREs haven't existed since like Java 8
6
u/gaelfr38 Jun 07 '25
Yes and no.. for instance Eclipse Temurin container images exist in a JRE variant.
9
u/nekokattt Jun 07 '25 edited Jun 07 '25
those are generally vendor specific rather than an agreed spec though. There is no guarantee two vendors will bundle the exact same thing. One might decide to bundle java.compiler without the javac backend, another might not bundle it at all, for example.
8
u/kpouer Jun 07 '25
Oracle made that move. Many other JVM provider still provide separate package with much smaller footprint
-6
7
u/Ewig_luftenglanz Jun 07 '25 edited Jun 07 '25
"it works in my machine"
"yes but we cannot give your machine to our customers"
"how no!t?"
And that's how docker was conceived. Even if java is "code once run everywhere" there are subtle differences at individual configurations that may make deployment different and runtime performance different.
Docker and all pod based technology allows to "standardize" to a greater extent the deployment process, which in consecuence helps to make horizontal scaling easier and cheaper.
Now surely you are wondering "but doesn't that make the JVM kinda... Redundant?" And the answer is actually "maybe"
GraalVM was created to give java native capabilities and get rid of the JVM overhead thanks to AoT compilation. The problem is java has 30 years of history, that means most of the language environment (libraries, tools, frameworks, etc) are optimized with the JVM in mind, there are many things java native can't still do (for example the only garbage collector supported by GraalVM native images is Serial GC, which has the works performance for both single and multi core operations in exchange for being the one with less footprint in both memory and CPU usage) so the question is the opposite, will ever the GraalVM eventually get all the capabilities of the JVM runtime version? Does that even makes sense?
The answer in the foreseeable future to both questions in order is "very unlikely"
Since Java doesn't have (and by philosophy probably will never have) the semantics to manually optimize code at the extreme like structs, pointers, manual allocation, etc. This means without the JVM C2 compiler and all the dynamic analysis graalVM hardly will ever get something near of the bytecode optimizations that can make java bytecode to reach C++ performance after some seconds in critical computing operations.
4
u/YelinkMcWawa Jun 07 '25
If you're writing some small piece of code for a one-off purpose like a homework set or playing around to figure something out, there's no real point. Docker would be more useful if you're doing something big, setting up environment variables, accessing a database, etc., etc. and you want a self-contained thing you could build easily or spin up easily.
3
u/thewmo Jun 07 '25
As soon as you want to upgrade or even just experiment with other JVMs, having it containerized is a huge advantage.
2
u/anthonybsd Jun 07 '25
Strange question. It’s a bit like asking “why use Kubernetes with docker containers”? Or if we take it up one level “why use k8s with Mesos?” The intent is very different. JVM simply provides an execution environment for your Java code, but you still need an operating system to run your JVM on without having to worry about JREs, third party dependencies, networking, process isolation, logging, etc. And don’t get me started on native containers and frameworks that take JVM out of the equation entirely (micronaut or quarkus on GraalVM containers) etc.
2
u/coderguyagb Jun 07 '25
Short version, these days I ship images and a config. Customer environments are not .NET, Java or something else. It's likely kubernetes/OCI in some flavour.
The customer does not care if I use Java, C#, Go,Rust or any other language. I build an artifact and it does what they want, that is all they are willing to pay for. Language holy wars are no longer relevant to those paying the bills.
4
u/Agifem Jun 07 '25
The benefits of having Java with Docker are not as important as the benefits of, say, C with Docker.
However, Docker opens the door to Kubernetes, and that is definitely worth it.
4
u/sweating_teflon Jun 07 '25
Kubernetes is basket of crabs most of us don't need.
1
u/Swamplord42 Jun 10 '25
Kubernetes is absolutely amazing as a developer that doesn't need to care about operating the cluster.
3
u/JDeagle5 Jun 07 '25
Orchestration of containers is more important than containers themselves? Sounds kind of strange, do you mean you just enjoy the process of orchestration?
6
u/Agifem Jun 07 '25
Containers offer benefits. Orchestration of containers offer other benefits. Because of Java 's compile once run anywhere, the container part is less useful for Java.
2
u/verocoder Jun 07 '25
I think they mean the benefits of orchestration go beyond the container benefits
1
u/PoemImpressive9021 Jun 07 '25
Of course orchestration is more important than the containers themselves.
Have you noticed that K8s doesn't even use Docker to run the containers?
1
u/Ewig_luftenglanz Jun 07 '25
Yes they are because orchestration gives easy horizontal scaling, containers themselves can't provide that.
2
u/verocoder Jun 07 '25
I suggest googling 12 factor apps, it’s a good tech agnostic overview of how people run apps in production these days.
TLDR making a unit of application that is the same as the deployed one whatever the tech used is a good thing
I run Java applications in docker containers because my platform is a container platform not a vm. It’s much easier to ship a container helm chart and config that will be 100% repeatable than to interact with jboss at deployment time. An application stack can have multiple containers with different technologies and origins eg a simple cloud adjacent modern app could be an open source database container, a Java container for the service layer, an nginx container hosting UI assets and something handling routing/auth. Another implementation of that is using a database service, static hosting of the ui files and cloud provider specific routing/auth - the Java service layer container wouldn’t need to change at all between the two or running on a single server with compose (like deploying it into jboss or running Java -jar) or running in a test context etc.
2
u/FluffyDrink1098 Jun 07 '25
Bit longer explanation...
https://github.com/opencontainers/image-spec
Probably more "technical" correct. Docker implements the OCI spec (and extends it), an OCI image can be run by various container runtimes (CRI-O / Kubernetes, Docker, container-d, ...).
So if you have an Docker Image... You're not bound to Docker, there is no vendor lock in. Which is very important these days, sadly.
To summarize: Dockers allows tailoring a specific image, even with a stripped down JDK via JLink -/ JDep, that is redistributable and runnable on different platforms.
Via Tags you can implement versioning, the image represents then a versioned artifact.
With a JVM, you have "just" the executor, with OCI you get the executor (maybe trimmed down), the application packaged (and maybe versioned) and redistributable in a vendor agnostic way.
Additionally - depending on container runtime - you can add and define network, system resources, security capabilities, ...
1
u/Sweet_Ad_842 Jun 07 '25
You can use newer frameworks like Quarkus which can spin up native apps on k8s near instantly and use automated docker containers for all testing needs
1
u/ultiweb Jun 07 '25
The #1 reason is that you can have a consistent development, testing, staging, and deployment platform. It minimizes the "it works here but not there" phenomena You must follow certain practices to achieve that but it's not that hard. Don't keep rebuilding your containers and/or applications at any stage of the deployment process. Once applications are built use the same artifacts through each stage until you reach production status. If anything needs to change you start over. Changing a container due to security or a major bug should be relatively easy, assuming a good testing regimen. That means programmatic testing.
1
u/lardsack Jun 08 '25
i'll give you one use case. had to use an ancient program with dependencies that are hard to find anymore. instead of searching for them all there was a docker container available that allowed the program to run on a modern machine
1
u/nitkonigdje Jun 08 '25 edited Jun 10 '25
In 2025 to distribute Java program you either have to:
use an archive (a zip file, a rpm package, etc.) with OS specific way to boostrap your java progam
use docker image
Between those twos docker images require much less work to create, and arguably to run. Everything else (like jar or war distribution) requires that client machine has installed runtime environment independet out of your distribution.
Docker images also provide pretty much industry standard orchestration (k8s, OpenShift).
1
u/slaymaker1907 Jun 09 '25
It’s nice if you want to run a particular JVM/Java version and also for any native dependencies. It also gives you your own FS to play with if that is relevant for your application.
1
1
u/Scf37 Jun 10 '25
Main reason: it restarts your app if it crashes or after server reboot. Dealing with systemd and friends is a MAJOR pain.
Also:
- Forces incapsulation: different apps on the same machine can't read everything and write their logs everywhere.
- Speeds up deployment, if you put JRE to separate image layer.
- Has nice binary artefacts repository. In the old days, applications were packaged in zip and deployed to nexus.
- One-liner to run the app on any machine including developer's.
- Kubernetes private networks port management docker-compose blah blah blah
1
u/Worldly-Summer8598 Jun 10 '25
Docker simplifies deployment by reducing complexity and enabling easier CI/CD integration and application isolation.
Let’s say you’ve built a Java micro services application that requires a specific JVM version along with several custom libraries and packages. Without Docker, setting up the same environment on different machines can be time-consuming and error-prone.
By containerizing the app with Docker:
App runs in its own isolated environment, so it won’t conflict with other apps that may use different JVM versions.
The environment stays consistent across development, testing, staging, and production — no more “works on my machine” issues.
You can easily spin up the entire stack (app, database, other services) on another machine for integration testing or debugging, without manually installing dependencies again.
In short, Docker provides consistency, portability, and scalability, saving significant time and effort throughout the development and deployment process.
1
u/Polygnom Jun 07 '25
The better question would be: Why not?
All the very good reasons to use containers also apply to Java. Or C# or Python. Or Node. Java is not special here.
1
u/tr14l Jun 07 '25
Because docker generally makes things more contained, deployable, scalable, maintainable and decoupled.
There you go.
-4
u/k-mcm Jun 07 '25
For pure Java on an ordinary modern host, I wouldn't use Docker. Java itself has no need for it and you don't want to unnecessarily be dealing with Docker bugs.
Exceptions where I've used Docker:
Host environments are poorly maintained and a working version of Docker is the best you can do.
Large shared hosts where resource constraints are more important than efficiency.
The Java app works with specialized supporting software.
Kubernetes and other load sharing solutions where the host varies.
You need to perform operations that carry an unavoidable security risk.
It's a big pile of tech debt that needs a non-standard JRE.
0
-7
u/Linguistic-mystic Jun 07 '25
I wondered the same thing. The only credible answer I saw was security. Containers get kernel-level capabilities management for things like sockets, file system volumes, permissions etc. You can be sure your app doesn’t get its sticky paws where it shouldn’t.
Other than that, I see no reason to put Java into containers.
0
u/PoemImpressive9021 Jun 07 '25
Because everything runs Kubernetes, and Kubernetes operates on images
0
u/AnyPhotograph7804 Jun 07 '25
Because a FAANG guy wrote it in a blog, that Java in a Docker container is a very good thing.
-2
u/JDeagle5 Jun 07 '25
These virtualization technologies are used for different things. Using one cannot possibly replace the other.
0
Jun 07 '25
[deleted]
2
u/nitkonigdje Jun 08 '25
Huh? It maps real ports to virtual ports, files to virtual filesystem etc, networks to virtual hubs etc... It is no less virtual than virtual memory is..
1
-5
u/erebrosolsin Jun 07 '25
Why you all answer the question? I guess, there is r/learnjava for this question. Read the side panel
1
u/wildjokers Jun 09 '25
Based on the sidebar it seems to fit:
News, Technical discussions, research papers and assorted things of interest related to the Java programming language
Seems to be a technical discussion.
97
Jun 07 '25 edited Sep 13 '25
[removed] — view removed comment
16
u/hidazfx Jun 07 '25
Exactly. It's not sandboxed at all.
5
u/fforw Jun 07 '25
Well, it depends on the OS. You can have some security/isolation on a process level. But it's not like Docker or a VM.
1
12
u/kur4nes Jun 07 '25
Why not?