Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker container vs Java Virtual Machine

Is it true to say that to a high degree what is now done in docker containers can also be done in java with jvm if someone wanted to ?

Besides being able to write an application in your own language and having much customisation flexibility does docker basically do what Java has been doing with its virtual machine for ages ? i.e. it provides executable environment separate from the underlying OS.

like image 243
Shady Programmer Avatar asked Dec 20 '16 22:12

Shady Programmer


2 Answers

Generally Docker containers cannot be done "within Java" because Docker serves to encapsulate the application, and "within Java" is the code being loaded after the JVM launches.

The JVM is already running when it parses the class it will search for the main method. So encapsulation at the process level can't be done because the process (the JVM) is already running.

Java has encapsulation techniques which do provide protection between various Java elements (see class loader hierarchies in Tomcat, for an example); but those only isolate "application plugins" from each other, the main process that is running them all is Tomcat, which is really a program loaded into an already running JVM.

This doesn't mean you can't combine the two to achieve some object, it just means that the types of isolation provided between the two products isn't interchangeable.

like image 171
Edwin Buck Avatar answered Sep 21 '22 23:09

Edwin Buck


what is now done in docker containers can also be done in java with jvm someone wanted to

Short Answer: No. You could wrap a docker container around your JVM, but you cannot wrap a JVM around a docker container, non-trivially.

docker basically do what Java has been doing with its virtual machine for ages ? i.e. it provides executable environment separate from the underlying OS.

Docker containers provide isolation from other containers without introducing a virtualisation layer. Thus, they are different and more performant than VMs.

like image 42
IgnoranceIsBliss Avatar answered Sep 18 '22 23:09

IgnoranceIsBliss