Accessing Host Java from Docker container

做~自己de王妃 提交于 2020-12-27 06:21:16

问题


I have Java installed in my docker host. Now I want that to be able to my docker containers. I don't want to install again on the containers. Do we have any workaround for that?


回答1:


Well it defeat the purpose of using Docker that is to decouple your container from the host.

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

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.




回答2:


I guess what you looking for is GraalVM which is built and managed by Oracle. 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.)

Bundling JDK or JRE within your app container can soon make your containers extremely bloated. Using GraalVM is a good way to tackle this problem.

Alternatively, you can have the JDK in a different container and mount the JAVA_HOME path as a volume in your app container(s). So you have one JDK container being shared between multiple app containers.



来源:https://stackoverflow.com/questions/53650594/accessing-host-java-from-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!