在centos 7 dockerfile中安装java 8

piwo6bdm  于 11个月前  发布在  Docker
关注(0)|答案(2)|浏览(227)

我刚刚看了这个问题:How to define OpenJDK 8 in CentOS based Dockerfile?
我尝试了建议的答案,但没有得到预期的结果。

FROM centos:7

RUN yum install -y \
       java-1.8.0-openjdk \
       java-1.8.0-openjdk-devel

ENV JAVA_HOME /etc/alternatives/jre
RUN yum install maven
RUN yum install curl 
RUN yum install -y unzip

字符串
我正在通过docker build -t container_image:latest -f DockerFile.build .构建映像,然后当我运行docker run -it {image_id} /bin/bash并执行java --version时,我得到bash: java: command not found。有人能帮助我看看我在这里做错了什么吗?
另外,当我尝试通过yum install java-1.8.0-openjdk从容器中安装jdk时,我得到以下结果

java --version
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

rkue9o1l

rkue9o1l1#

这个修好了

FROM centos

RUN yum -y update
RUN yum -y remove java
RUN yum install -y \
       java-1.8.0-openjdk \
       java-1.8.0-openjdk-devel

RUN yum install -y maven
RUN yum install -y curl 
RUN yum install -y unzip

字符串

zour9fqk

zour9fqk2#

从@Evan上面的回答中稍微编辑了一个版本,供那些得到Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist的人使用

RUN cd /etc/yum.repos.d/
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
RUN yum -y update
RUN yum -y remove java
RUN yum install -y \
       java-1.8.0-openjdk \
       java-1.8.0-openjdk-devel

RUN yum install -y maven
RUN yum install -y curl
RUN yum install -y unzip

字符串

相关问题