简体   繁体   English

Docker 容器与 Java 虚拟机

[英]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 ?如果有人愿意,现在在 docker 容器中所做的事情在很大程度上也可以在 java 中使用 jvm 来完成,这是真的吗?

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 ?除了能够用您自己的语言编写应用程序并具有很大的定制灵活性之外,docker 是否基本上可以做 Java 多年来对其虚拟机所做的事情? ie it provides executable environment separate from the underlying OS.即它提供了与底层操作系统分离的可执行环境。

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.通常Docker容器不能在“Java内”完成,因为Docker用于封装应用程序,而“Java内”是JVM启动后加载的代码。

The JVM is already running when it parses the class it will search for the main method. JVM 在解析将搜索main方法的类时已经在运行。 So encapsulation at the process level can't be done because the process (the JVM) is already running.因此无法在进程级别进行封装,因为进程(JVM)已经在运行。

Java has encapsulation techniques which do provide protection between various Java elements (see class loader hierarchies in Tomcat, for an example); Java 具有封装技术,可以在各种 Java 元素之间提供保护(例如,请参见 Tomcat 中的类加载器层次结构); 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.但是那些只是将“应用程序插件”彼此隔离开来,运行它们的主要进程是 Tomcat,它实际上是一个加载到已经运行的 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.这并不意味着您不能将两者结合起来实现某个目标,只是意味着这两种产品之间提供的隔离类型不可互换。

what is now done in docker containers can also be done in java with jvm someone wanted to现在在 docker 容器中完成的工作也可以在 java 中使用有人想要的 jvm 完成

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 容器包装在 JVM 周围,但不能将 JVM 包装在 docker 容器周围,这很重要。

docker basically do what Java has been doing with its virtual machine for ages ? docker 基本上做 Java 多年来一直在用它的虚拟机做的事情? ie it provides executable environment separate from the underlying OS.即它提供了与底层操作系统分离的可执行环境。

Docker containers provide isolation from other containers without introducing a virtualisation layer. Docker 容器在不引入虚拟化层的情况下提供与其他容器的隔离。 Thus, they are different and more performant than VMs.因此,它们与 VM 不同且性能更高。

Docker can perform several things that the Java JVM cannot do however, programming in Java and running on the JVM will provide several of the advantages of running in a Docker container. Docker 可以执行 Java JVM 无法完成的一些事情,但是,使用 Java 编程并在 JVM 上运行将提供在 Docker 容器中运行的几个优点。 I work on a large Java project and this project is 20 years old.我从事一个大型 Java 项目,这个项目已有 20 年历史。 We have been evolving and fixing our application without any tools or compatibility issues for all these years.这些年来,我们一直在发展和修复我们的应用程序,没有任何工具或兼容性问题。 Also, as a bonus, the application is platform independent.此外,作为奖励,该应用程序是独立于平台的。 Several components of it can run in both Windows and Linux.它的几个组件可以在 Windows 和 Linux 中运行。 Because no effort was made initially to build a multiplatform application, there is one component that cannot run on Linux.因为最初没有努力构建多平台应用程序,所以有一个组件不能在 Linux 上运行。 But it would be relatively easy to make it work on that platform.但是让它在那个平台上工作相对容易。 It would have been much more difficult to do the same thing using C or C++ and associated toolchain.使用 C 或 C++ 和相关工具链做同样的事情会困难得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM