Docker alpine + oracle java:找不到java [英] Docker alpine + oracle java: cannot find java
问题描述
我一直在尝试用Oracle Java(而不是openjdk)创建一个基于阿尔卑斯的docker镜像。我被特别要求在这里创建我们自己的图像。
I've been trying to create an alpine-based docker image with Oracle Java (rather than openjdk). I have been specifically asked to create our own image here.
这是我提出的Dockerfile:
This is the Dockerfile I've come up with:
FROM alpine:3.6
RUN apk add --no-cache curl wget
RUN mkdir /opt/ && \
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie"\
http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz && \
tar xvf jdk-8u131-linux-x64.tar.gz -C /opt/ && \
rm jdk-8u131-linux-x64.tar.gz && \
ln -s /opt/jdk1.8.0_131 /opt/jdk
ENV JAVA_HOME /opt/jdk
ENV PATH $PATH:/opt/jdk/bin
RUN echo $JAVA_HOME && \
echo $PATH
RUN which java
RUN java -version
有一些不必要的命令(比如回显JAVA_HOME dir),这些命令被添加以帮助调试,但现在我卡住了: RUN哪个java
按预期返回 / opt / jdk / bin / java
,但 RUN java -version
返回 / bin / sh:java:not found
。
There are some unnecessary commands (like echoing the JAVA_HOME dir) which were added to help with debugging, but now I'm stuck: RUN which java
returns /opt/jdk/bin/java
as expected, but RUN java -version
returns /bin/sh: java: not found
.
我尝试过一些事情,包括将可执行文件符号链接到/ usr / bin,无济于事。
I've tried a few things, including symlinking the executable(s) into /usr/bin, to no avail.
我缺少什么?
编辑:
最终输出来自docker的是:
命令'/ bin / sh -c java -version'返回非零代码:127
最终编辑:
感谢diginoise让我加入MUSL vs libc。我发现在我的Dockerfile中添加以下内容可以让我构建一个工作映像:
Thanks to diginoise for putting me on to MUSL vs libc. I found adding the following to my Dockerfile allowed me to build a working image:
RUN apk --no-cache add ca-certificates && \
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-2.25-r0.apk && \
apk add glibc-2.25-r0.apk
发现于: https://github.com/sgerrand/alpine-pkg-glibc
推荐答案
你无法达到你想要的效果。
You cannot achieve what you want.
Alpine Linux使用MUSL作为标准C库。
Alpine Linux uses MUSL as a Standard C library.
Oracle的Linux for Linux依赖于GNU标准C库(gclib)。
Oracle's Java for linux depends on GNU Standard C library (gclib).
有理论方法,但是它并不像你想象的那么微不足道。
There is theoretical way, but it is not as trivial as you think.
请参阅此链接
您可以找到使用OracleJDK运行的Alpine图像示例这里和这里。这两个例子都是添加缺少的GNU C库。
You can find examples of Alpine images running with OracleJDK here and here. Both examples are adding the missing GNU C library.
JDK源代码尚未移植到Alpine Linux,或者更具体地说,移植到musl C库。也就是说,事实证明,关于Alpine Linux的内容与JDK源代码的不同之处在于C库。
the JDK source code has not yet been ported to Alpine Linux, or more specifically, the musl C library. That is, it turns out that the thing about Alpine Linux that sticks out/is different from a JDK source code perspective is the C library.
简而言之使用官方Oracle Java Docker镜像
这篇关于Docker alpine + oracle java:找不到java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!