8

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?

freeman
  • 399
  • 1
  • 3
  • 11
  • A JVM does not give you an isolated filesystem or an isolated networking stack. OTOH it is easier/safer to deploy as a non-root user. – Thilo Jan 05 '16 at 03:49
  • 2
    Comparing a JVM and an actual VM is comparing apples and oranges; the JVM is simply an interpreter (and possibly JIT compiler) for Java, a VM is a full-blown virtual machine, with its own hardware and OS. – Colonel Thirty Two Jan 05 '16 at 03:51
  • Duplicate with https://stackoverflow.com/questions/34487094/why-use-docker-arent-java-files-like-war-files-already-running-on-jvm ? – Auzias Jan 08 '16 at 13:13

3 Answers3

7

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.

mattm
  • 5,851
  • 11
  • 47
  • 77
  • The JVM is not a level of virtualization... At least not in the same sense or level as Docker – David Brossard Jan 05 '16 at 04:07
  • 1
    Oh wow, I never knew V stood for virtualization. I just thought they put it there because it looked cool :-) The goal of the JVM was to abstract away compiled code from the specific architecture of the CPU and that's how bytecode came to be. But virtualization in the VMWare sense goes way way beyond that – David Brossard Jan 05 '16 at 04:48
5

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.

Vikram Tiwari
  • 3,615
  • 1
  • 29
  • 39
2

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.

David Brossard
  • 13,584
  • 6
  • 55
  • 88