java 在 docker 中更改 JAVA_HOME
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46277631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change JAVA_HOME in docker
提问by Shoreki
The legacy web application which I want to dockerise uses some old classes like com/sun/image/codec/jpeg/ImageFormatException
which were supported till Java SE7.
Now in the docker container default jdk getting (on installing tomcat-6 container) is
我想要 dockerise 的遗留 Web 应用程序使用了一些旧类,例如com/sun/image/codec/jpeg/ImageFormatException
Java SE7 之前支持的类。现在在 docker 容器中默认 jdk 获取(在安装 tomcat-6 容器时)是
java version "1.7.0_131"
OpenJDK Runtime Environment (IcedTea 2.6.9) (7u131-2.6.9-2~deb8u1)
OpenJdk doesn't support these classes
OpenJdk 不支持这些类
I used update-alternatives
to install Oracle Jdk7.80
我update-alternatives
以前装的是Oracle Jdk7.80
After loading container, on giving java -version
I am getting
装载集装箱后,java -version
我得到
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
However, echo $JAVA_HOME
after entering the container gives /docker-java-home/jre
which again points to OpenJdk. How can I set JAVA_HOME
to the Oracle Jdk home that I installed?
但是,echo $JAVA_HOME
进入容器后给出/docker-java-home/jre
which再次指向OpenJdk。如何设置JAVA_HOME
为我安装的 Oracle Jdk 主目录?
回答by dpr
You can simply set/change environment variables of your docker image by using the ENV
command in your Dockerfile:
您可以使用ENV
Dockerfile 中的命令简单地设置/更改docker镜像的环境变量:
ENV JAVA_HOME /path/to/java
回答by Dashrath Mundkar
If your base image contains by default OpenJDK and If you want to use OracleJDK in your image just add the below command to your dockerfile and build the image and boom your image will have oracle JDK.
如果您的基础镜像默认包含 OpenJDK,并且如果您想在您的镜像中使用 OracleJDK,只需将以下命令添加到您的 dockerfile 并构建镜像并繁荣您的镜像将拥有 oracle JDK。
RUN yum -y remove java***
RUN yum install -y jdk-8u212-linux-x64.rpm && \
echo "JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")" | tee
-a /etc/profile && source /etc/profile && echo $JAVA_HOME && \
rm jdk-8u212-linux-x64.rpm && \
alternatives --set java /usr/java/jdk1.8.0_212-amd64/jre/bin/java