美文网首页
解决alpine使用oracle java时报java not

解决alpine使用oracle java时报java not

作者: 风吹路过的云 | 来源:发表于2020-04-29 09:55 被阅读0次

    镜像做好跑起来后,在里面执行java -version,会报类似如下的错误:

    The command '/bin/sh -c javac -version' returned a non-zero code: 127
    

    ENV已经加了JAVA_HOME,JAVA_HOME也已经加到PATH里去了,在容器里which java也打出正常的路径了,echo $JAVA_HOME也是正常的,但就是报java not found,好郁闷
    哈哈,后来通过一篇文章找到了答案,文章来源:http://www.hackerav.com/?post=50809

    You cannot achieve what you want.
    Alpine Linux uses MUSL as a Standard C library.
    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.
    

    附上,可以正常使用的Dockerfile,如下:

    FROM jlesage/firefox
    # desc:make the base image for xx-aa-browser project
    # author: aa@xx.com
    # time: 2020-04-22 10:16
    COPY sgerrand.rsa.pub /etc/apk/keys/
    COPY *.apk /tmp/
    RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
        && sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
        && apk update \
        && apk upgrade \
        && apk add busybox-extras \
        && mkdir -p /opt/server /data/tomcat_logs \
        && apk --no-cache add ca-certificates \
        && apk add /tmp/*.apk \
        && /usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8
    ADD geckodriver /usr/bin/
    ADD jdk1.8.0_162.tar.gz /opt/server/
    ENV LC_ALL=en_US.UTF-8
    ENV JAVA_HOME=/opt/server/jdk1.8.0_162
    ENV CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
    ENV PATH="$JAVA_HOME/bin:${PATH}"
    EXPOSE 8080
    

    基于jlesage/firefox镜像的原因是因为java项目里要调用firefox内核,所以jdk是自己加上去的,一开始没注意到我们公司使用的jdk是oracle jdk。
    jlesage/firefox镜像是基于alpine的。

    Dockerfile文件所在目录的文件如下:

    [root@8d224-docker browser-base]# ll
    total 270736
    -rw-r--r--. 1 root root       904 Apr 28 23:02 Dockerfile
    -rwxr-xr-x. 1 root root   7008696 Oct 12  2019 geckodriver
    -rwxr-xr-x. 1 root root   4412098 Apr 28 21:09 glibc-2.31-r0.apk
    -rwxr-xr-x. 1 root root   1007404 Apr 28 22:00 glibc-bin-2.31-r0.apk
    -rwxr-xr-x. 1 root root   7713411 Apr 28 21:13 glibc-i18n-2.31-r0.apk
    -rw-r--r--. 1 root root 189682037 Apr 22 17:26 jdk1.8.0_162.tar.gz
    -rw-r--r--. 1 root root       451 Apr 28 21:54 sgerrand.rsa.pub
    

    参考资料:
    https://github.com/sgerrand/alpine-pkg-glibc
    http://www.hackerav.com/?post=50809

    相关文章

      网友评论

          本文标题:解决alpine使用oracle java时报java not

          本文链接:https://www.haomeiwen.com/subject/fbawwhtx.html