简体   繁体   English

从 Docker 容器访问主机 Java

[英]Accessing Host Java from Docker container

I have Java installed in my docker host.我在我的 docker 主机中安装了 Java。 Now I want that to be able to my docker containers.现在我希望它能够进入我的 docker 容器。 I don't want to install again on the containers.我不想在容器上再次安装。 Do we have any workaround for that?我们有什么解决方法吗?

Well it defeat the purpose of using Docker that is to decouple your container from the host.好吧,它违背了使用 Docker 的目的,即将容器与主机分离。

If you are looking for a workaround you can probably just mount your Java host installation directory in you container but is better to use the same OS both in the container and in the host如果您正在寻找解决方法,您可能只需将 Java 主机安装目录挂载到容器中,但最好在容器和主机中使用相同的操作系统

I think is a not worth it and you don't have to "install" Java just start from an Image (or create one yourself) that already contains Java, with open jdk is pretty simple.我认为这是不值得的,你不必从一个已经包含 Java 的图像(或自己创建一个)开始“安装”Java,打开 jdk 非常简单。

I guess what you looking for is GraalVM which is built and managed by Oracle.我猜你要找的是由 Oracle 构建和管理的GraalVM They have community and enterprise editions.他们有社区版和企业版。

Take a look at this blog -> https://blog.softwaremill.com/small-fast-docker-images-using-graalvms-native-image-99c0bc92e70b (walks through on how to create small docker containers for Java application using graalvm.)看看这个博客 -> https://blog.softwaremill.com/small-fast-docker-images-using-graalvms-native-image-99c0bc92e70b (介绍如何使用 graalvm 为 Java 应用程序创建小型 docker 容器.)

Bundling JDK or JRE within your app container can soon make your containers extremely bloated.在您的应用程序容器中捆绑 JDK 或 JRE 很快会使您的容器变得非常臃肿。 Using GraalVM is a good way to tackle this problem.使用 GraalVM 是解决这个问题的好方法。

Alternatively, you can have the JDK in a different container and mount the JAVA_HOME path as a volume in your app container(s).或者,您可以将 JDK 放在不同的容器中,并将 JAVA_HOME 路径作为卷安装在您的应用程序容器中。 So you have one JDK container being shared between multiple app containers.因此,您有一个 JDK 容器在多个应用程序容器之间共享。

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

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