问题
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