简体   繁体   English

是否有必要在Java中使用Docker?

[英]Is it necessary to use Docker in Java?

As Docker is a very hot tech currently, but I just wonder if it is necessary for Java? 由于Docker是当前非常热门的技术,但我只是想知道Java是否必要? I list my reasons below, and any feedback is welcomed: 我在下面列出了我的原因,欢迎任何反馈:

  • JVM just like a VM, which separate application from OS JVM就像VM,将应用程序与OS分开
  • Maven, manage dependencies Maven,管理依赖项
  • Spring Boot, support embed J2EE servelet containers like tomcat, all applications can be output as standard JAR file. Spring Boot,支持嵌入tomcat之类的J2EE servelet容器,所有应用程序都可以作为标准JAR文件输出。

So, except you need to install JDK yourself, everything else is consistent and organized. 因此,除了需要自己安装JDK之外,其他所有内容都是一致且井井有条的。 I compare Java and Docker like below: 我将Java和Docker进行如下比较:

  • JAR -> Image JAR->图片
  • JVM -> VM JVM->虚拟机

So, Docker really mean something for Java? 那么,Docker对Java真的意味着什么?

Docker is not necessary for Java. Docker对于Java而言不是必需的。 You can run a JVM on an operating system without worrying about Docker. 您可以在操作系统上运行JVM,而无需担心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与JVM相似之处在于它们都是虚拟化级别,但是将Docker提供的虚拟化与JVM相同可能没有帮助。 Docker is really a convenience tool for packaging together multiple applications/services into a container that is portable. Docker实际上是将多个应用程序/服务打包到可移植容器中的便捷工具。 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. 如果使用不同版本的JVM运行jar文件,则可能会得到不同的结果。 For example, if the jar includes Java 8 functions but you try running on a Java 7 VM, you will encounter exceptions. 例如,如果jar包含Java 8函数,但您尝试在Java 7 VM上运行,则会遇到异常。 The point of Docker is that you can control versions so this does not happen. Docker的要点是您可以控制版本,因此不会发生这种情况。

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? 您是否使用Java以外的任何数据库和库?

Docker is mostly for simplification of development process even when the one dev's machine differs from other. Docker主要是为了简化开发流程,即使一个开发人员的机器与其他开发人员的机器不同。 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. 尽管Java通过使用jvm来解决此问题,但请考虑以下情况:您使用的是Java新版本上的函数,而您的同级计算机上却有Java旧版本。 God forbid its your server. 上帝禁止它为您服务。

Same applies when you are launching other services along with your java app. 当您与Java应用程序一起启动其他服务时,同样适用。 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. 尽管Java内部库本身由maven维护,但是它们无法控制您依赖的其他服务。

In short, no, Docker is not necessary for Java. 简而言之,不,对于Java而言,Docker并不是必需的。 Its not necessary for any language actually. 实际上,对于任何语言而言,它都是不必要的。 It just creates consistency across multiple devs and production and other services, and hence the popularity. 它只是在多个开发人员,生产和其他服务之间建立了一致性,因此很受欢迎。

You do not have to use Docker in Java but not for the reasons you gave. 您不必在Java中使用Docker,但不必出于您给出的原因。

Docker is not similar to a JVM! Docker与JVM不同! Docker is about having an isolated easily deployable environment that is configurable from outside, that can be started, stopped, and cloned easily. Docker的目的是要有一个隔离的,易于部署的环境,该环境可以从外部进行配置,并且可以轻松启动,停止和克隆。

Docker is similar to other virtualization technologies such as VirtualBox or VMWare but definitely not the JVM. Docker与其他虚拟化技术(例如VirtualBox或VMWare)相似,但绝对不是JVM。

You can use Docker to select your OS, firewall settings, version of JVM and even more. 您可以使用Docker选择您的操作系统,防火墙设置,JVM版本等等。 You can use Docker to deploy 1 version or 1000 versions of your software. 您可以使用Docker部署1个或1000个版本的软件。 You can use Docker to give a fully-working environment to a customer or colleague. 您可以使用Docker为客户或同事提供完整的工作环境。

JVMs do not do that. JVM不会这样做。

Oh and there are security implications too. 哦,还有安全隐患。

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

相关问题 何时使用AtomicReference(Java)? 真的有必要吗? - When to use AtomicReference (Java)? Is it really necessary? 是否真的有必要使用“监视器”对象(java) - Is it ever truly necessary to use a “monitor” object (java) 将 Java 与 Airflow 和 Docker 一起使用 - Use Java with Airflow and Docker 为了使用Eclipse,是否需要修改PATH,CLASSPATH和JAVA_HOME? - Is it necessary to modify PATH, CLASSPATH, and JAVA_HOME in order to use Eclipse? 为什么在Java中将字符串添加到ArrayLists所需的转换或使用泛型? - Why is either casting or the use of generics necessary for adding Strings to ArrayLists in Java? 为什么在Java while循环中必须使用“ break”和“ continue”语句? - Why is it necessary to use “break” and “continue” statements in Java while loops? 是否有必要在可能由单个线程调度程序修改的字段上使用Java同步? - Is it necessary to use Java synchronization on a field that might be modified by a single thread scheduler? 使用rx java加载参考数据,但在必要时阻止 - Use rx java to load reference data but blocking if necessary 要使用Java中的“ saveToFile”方法,需要导入什么类? - What class is necessary to import for the use of the “saveToFile” method in Java? Java中的软件包-必要吗? - Packages in java - necessary?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM