Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it necessary to use Docker in Java?

Tags:

java

docker

As Docker is a very hot tech currently, but I just wonder if it is necessary for Java? I list my reasons below, and any feedback is welcomed:

  • JVM just like a VM, which separate application from OS
  • Maven, manage dependencies
  • Spring Boot, support embed J2EE servelet containers like tomcat, all applications can be output as standard JAR file.

So, except you need to install JDK yourself, everything else is consistent and organized. I compare Java and Docker like below:

  • JAR -> Image
  • JVM -> VM

So, Docker really mean something for Java?

like image 444
freeman Avatar asked Jan 05 '16 03:01

freeman


People also ask

Why Docker is used in Java?

Docker makes it easier to provide a consistent development environment for your whole team, particularly when your team must frequently shift from one environment to another. Your team can easily use the same OS, the same language run-time environment, and the same system libraries regardless of the host OS.

Do I need to use Docker?

Docker is very useful for web applications running on a server or console-based software. But if your product is a standard desktop application, especially with a rich GUI, Docker may not be the best choice.

Does Docker work with Java?

You can use Docker to run a Java application in a container with a specific runtime environment. This tutorial describes how to create a Dockerfile for running a simple Java application in a container with OpenJDK 17. It also shows how to create a Docker image with your application to share it with others.

Is Docker necessary for developers?

Docker is the de facto standard for containerizing apps, and with an increasing number of software projects migrating to containers, it is crucial for engineers and DevOps teams to understand how to build, deploy, and secure Docker environments effectively.


3 Answers

Docker is not necessary for Java. You can run a JVM on an operating system without worrying about Docker.

Docker is similar to a JVM in that they are both a level of virtualization, but it is probably not helpful to think of the virtualization provided by Docker as the same as the JVM. Docker is really a convenience tool for packaging together multiple applications/services into a container that is portable. It allows you to build the same virtual environment on multiple possibly different machines, or to destroy a virtual environment and restart it.

If you run a jar file with different versions of the JVM, you may get different results. For example, if the jar includes Java 8 functions but you try running on a Java 7 VM, you will encounter exceptions. The point of Docker is that you can control versions so this does not happen.

like image 186
mattm Avatar answered Oct 23 '22 10:10

mattm


Depends. How much version support does your code has? How do you deploy your code? Do you use any databases and libraries other than java?

Docker is mostly for simplification of development process even when the one dev's machine differs from other. While java takes care of that by using jvm, think of a case when you are using functions that are on a newer java version, but your peer has an older java version on his machine. God forbid its your server.

Same applies when you are launching other services along with your java app. They will be databases and other services which will be versioned. Though internal libraries of java are themselves maintained by maven, they have no control over other services that you are dependent upon.

In short, no, Docker is not necessary for Java. Its not necessary for any language actually. It just creates consistency across multiple devs and production and other services, and hence the popularity.

like image 45
Vikram Tiwari Avatar answered Oct 23 '22 09:10

Vikram Tiwari


You do not have to use Docker in Java but not for the reasons you gave.

Docker is not similar to a JVM! Docker is about having an isolated easily deployable environment that is configurable from outside, that can be started, stopped, and cloned easily.

Docker is similar to other virtualization technologies such as VirtualBox or VMWare but definitely not the JVM.

You can use Docker to select your OS, firewall settings, version of JVM and even more. You can use Docker to deploy 1 version or 1000 versions of your software. You can use Docker to give a fully-working environment to a customer or colleague.

JVMs do not do that.

Oh and there are security implications too.

like image 2
David Brossard Avatar answered Oct 23 '22 10:10

David Brossard