我创建了一个通用的 docker 构建文件,其中包括 kubectl 和 Helm 等实用程序,但现在我想将采用 openjdk 与 Maven 一起添加到图像中,但是当我测试它时,Java 会因核心转储而崩溃。
这是 Dockerfile:
# docker-build-test-image
FROM docker:stable-git
ENV KUBERNETES_VERSION 1.11.10
ENV HELM_VERSION 2.14.0
ENV JDK_FILE=OpenJDK11U-jdk_x64_linux_hotspot_11.0.4_11.tar.gz
ENV JDK_DIR=/opt/jdk-11.0.4+11
ENV LANG=C.UTF-8
ENV MAVEN_FILE apache-maven-3.3.9-bin.tar.gz
RUN apk update && \
apk add --no-cache curl && \
apk add --no-cache bash && \
apk add --no-cache jq && \
apk add --no-cache gettext && \
apk add --no-cache wget
RUN apk add -U openssl curl tar gzip bash ca-certificates git && \
curl -L -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
curl -L -O https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk && \
apk add glibc-2.28-r0.apk && \
rm glibc-2.28-r0.apk
RUN curl "https://kubernetes-helm.storage.googleapis.com/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar zx && \
mv linux-amd64/helm /usr/bin/ && \
mv linux-amd64/tiller /usr/bin/ && \
helm version --client && \
tiller -version
RUN curl -L -o /usr/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl" && \
chmod +x /usr/bin/kubectl && \
kubectl version --client
# https://github.com/frol/docker-alpine-glibc/blob/master/Dockerfile
# Here we install GNU libc (aka glibc) and set C.UTF-8 locale as default.
RUN ALPINE_GLIBC_BASE_URL="https://github.com/sgerrand/alpine-pkg-glibc/releases/download" && \
ALPINE_GLIBC_PACKAGE_VERSION="2.28-r0" && \
ALPINE_GLIBC_BASE_PACKAGE_FILENAME="glibc-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \
ALPINE_GLIBC_BIN_PACKAGE_FILENAME="glibc-bin-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \
ALPINE_GLIBC_I18N_PACKAGE_FILENAME="glibc-i18n-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \
apk add --no-cache --virtual=.build-dependencies wget ca-certificates && \
echo \
"-----BEGIN PUBLIC KEY-----\
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApZ2u1KJKUu/fW4A25y9m\
y70AGEa/J3Wi5ibNVGNn1gT1r0VfgeWd0pUybS4UmcHdiNzxJPgoWQhV2SSW1JYu\
tOqKZF5QSN6X937PTUpNBjUvLtTQ1ve1fp39uf/lEXPpFpOPL88LKnDBgbh7wkCp\
m2KzLVGChf83MS0ShL6G9EQIAUxLm99VpgRjwqTQ/KfzGtpke1wqws4au0Ab4qPY\
KXvMLSPLUp7cfulWvhmZSegr5AdhNw5KNizPqCJT8ZrGvgHypXyiFvvAH5YRtSsc\
Zvo9GI2e2MaZyo9/lvb+LbLEJZKEQckqRj4P26gmASrZEPStwc+yqy1ShHLA0j6m\
1QIDAQAB\
-----END PUBLIC KEY-----" | sed 's/ */\n/g' > "/etc/apk/keys/sgerrand.rsa.pub" && \
wget \
"$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_I18N_PACKAGE_FILENAME" && \
apk add --no-cache \
"$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_I18N_PACKAGE_FILENAME" && \
\
rm "/etc/apk/keys/sgerrand.rsa.pub" && \
/usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 "$LANG" || true && \
echo "export LANG=$LANG" > /etc/profile.d/locale.sh && \
\
apk del glibc-i18n && \
\
rm "/root/.wget-hsts" && \
apk del .build-dependencies && \
rm \
"$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \
"$ALPINE_GLIBC_I18N_PACKAGE_FILENAME"
WORKDIR /tmp
RUN chmod 755 /opt
COPY $JDK_FILE /tmp/
RUN tar -zvxf /tmp/$JDK_FILE -C /opt/ \
&& rm /tmp/$JDK_FILE
ENV JAVA_HOME $JDK_DIR
ENV PATH "$PATH:$JDK_DIR/bin"
RUN wget --no-cookies --no-check-certificate "https://archive.apache.org/dist/maven/maven-3/3.3.9/binaries/$MAVEN_FILE"
RUN pwd
RUN ls -ltr
RUN tar -zvxf $MAVEN_FILE -C /opt/
RUN rm $MAVEN_FILE
ENV PATH "$PATH:/opt/apache-maven-3.3.9/bin"
COPY ./settings.xml /root/.m2/
JDK_FILE "OpenJDK11U-jdk_x64_linux_hotspot_11.0.4_11.tar.gz" 直接从https://adoptopenjdk.net/releases.html?variant=openjdk11&jvmVariant=hotspot下载。
一个非常简单的 Java 测试文件:
class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello, World");
}
}
我正在通过 GitLab 管道构建它:
image: ${BUILD_URL}/tools/build/docker-build-test-image/add-jdk:20191129.33
stages:
- build
build:
stage: build
script:
- java -version
- javac HelloWorld.java
- java HelloWorld
这是输出:
$ java -version
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.4+11)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.4+11, mixed mode)
#
# A fatal error has been detected by the Java Runtime Environment:
#
# [thread 20 also had an error]SIGSEGV
(0xb) at pc=0x00007f0c0251bba1, pid=18, tid=28
#
# JRE version: OpenJDK Runtime Environment (11.0.4+11) (build 11.0.4+11)
# Java VM: OpenJDK 64-Bit Server VM (11.0.4+11, mixed mode, tiered, compressed oops, serial gc, linux-amd64)
# Problematic frame:
# C [libc.so.6+0x117ba1]
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/libexec/abrt-hook-ccpp %s %c %p %u %g %t e %P %I %h" (or dumping to /builds/d4e/playground/revills/java_test/core.18)
#
# An error report file with more information is saved as:
# /builds/d4e/playground/revills/java_test/hs_err_pid18.log
[thread 19 also had an error]
#
# If you would like to submit a bug report, please visit:
# https://github.com/AdoptOpenJDK/openjdk-build/issues
#
/bin/bash: line 111: 18 Aborted (core dumped) java -version
你能告诉我我做错了什么吗?
干杯,史蒂夫