Why use Docker When You Can Just Use a Fat Jar?
Quickly choose whether to use Docker or a self contained fat jar
I saw a question on r/java that I thought was great. OP is deploying a fat jar that has everything OP's app requires, so the deploy is just a simple file copy. OP is also using Docker to deploy the entire environment along with the jar and wonders if it is worth it.
When to Use Docker
Docker is great when you are using Docker to deploy your entire server environment. If you have already container-ized your database, proxy and load balancer, it's a no brainer to add just one more docker image to container-ize your application. Your team already has the Docker infrastructure in place. Your environment already deploys with Docker. Unifying procedures keeps things simple.
3 Reasons to Use Docker
- Your application shrinks and grows. Adding/removing instances helps keep the bills down and the customers happy. This is particularly important on providers like AWS and DigitalOcean
- You deploy your application to a lot of different environments. Each different environment needs a couple tweaks to work.
- You don't want your deployment process to care about the state of server upgrades (like the JVM or Tomcat)
When to Use a Fat Jar
Fat jars are great. A fat jar bundles everything you need into one convenient archive, ready to go. Deploying a fat jar is easy: copy the jar to the server and run it. It's worth pointing out that fat jars combine very well with Docker - they are easier to use in the Docker context than containers.
3 Reasons to Use a Fat Jar
- When your environment is hand crafted. Fat jars are particularly useful both the jar and the environment define configuration
- When maintaining a Docker registry is significant overhead. If you're not already doing it, why add yet another infrastructure system?
- When you have an artifact repository (like Archiva or Nexus). These make it trivial to grab and deploy a particular version of your fat jar