Skip to content

Build OpenJDK

OpenJDK

构建精简版的 Docker 镜像并运行测试

1
2
3
4
5
6
FROM frolvlad/alpine-glibc:alpine-3.16_glibc-2.35
ENV LANG=C.UTF-8 \
    JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk \
    PATH=$PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin \
    run_foreground=true
RUN apk add --no-cache openjdk8 && rm -f /etc/apk/repositories
$ docker build -t openjdk8:alpine-glibc .
 ---> f1deb0c8af4b
Successfully built f1deb0c8af4b
Successfully tagged openjdk8:alpine-glibc

$ docker exec -it example bash
bash-5.1# java -version
openjdk version "1.8.0_345"
OpenJDK Runtime Environment (IcedTea 3.24.0) (Alpine 8.345.01-r0)
OpenJDK 64-Bit Server VM (build 25.345-b01, mixed mode)

PS:上述未配置时区,默认为 UTC

OpenJDK8u362

FROM frolvlad/alpine-glibc:alpine-3.16_glibc-2.35

ARG JAVA_PACKAGE=8.362.09-r1
ARG RUN_JAVA_VERSION=1.3.8

ENV JAVA_APP_DIR=/deployments \
    JAVA_MAJOR_VERSION=8 \
    TZ=Asia/Shanghai \
    LANG='zh_CN.UTF-8' LANGUAGE='zh_CN:zh' LC_ALL='zh_CN.UTF-8'
  # LANG='en_US.UTF-8' LANGUAGE='en_US:en'

# RUN echo "https://mirrors.aliyun.com/alpine/edge/testing/" >> /etc/apk/repositories \
#  && apk add --update tzdata curl openjdk8=${JAVA_PACKAGE} \

RUN apk add --update tzdata curl openjdk8=${JAVA_PACKAGE} \
 && set -eux \
 && ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \
 && echo ${TZ} > /etc/timezone \
 && rm -rf /var/cache/apk/* \
 && mkdir /deployments /usr/share/fonts/win \
 && chown 1001 /deployments \
 && chmod "g+rwX" /deployments \
 && chown 1001:root /deployments \
 && echo "securerandom.source=file:/dev/urandom" >> /usr/lib/jvm/default-jvm/jre/lib/security/java.security \
 && sed -i 's/^jdk.tls.disabledAlgorithms=SSLv3/#&/' /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/java.security \
 && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \
 && chown 1001 /deployments/run-java.sh \
 && chmod 540 /deployments/run-java.sh

# ADD simsun.ttc /usr/share/fonts/win/simsun.ttc
# ADD simsun.ttf /usr/share/fonts/win/simsun.ttf
COPY ./SimSun.ttf /usr/share/fonts/win/simsun.ttf

RUN chmod 777 /usr/share/fonts/win/simsun.* \
 && fc-cache -fv

USER 1001

CMD [ "/deployments/run-java.sh" ]

OpenJDK8u372

非限制权限和指定目录

FROM frolvlad/alpine-glibc:alpine-3.17_glibc-2.34

ARG JAVA_PACKAGE=8.372.07-r0

ENV JAVA_MAJOR_VERSION=8 \
    TZ=Asia/Shanghai \
    LANG='en_US.UTF-8' LANGUAGE='en_US:en'

RUN apk add --update tzdata curl openjdk8=${JAVA_PACKAGE} \
 && set -eux \
 && ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \
 && echo ${TZ} > /etc/timezone \
 && rm -rf /var/cache/apk/* \
 && echo "securerandom.source=file:/dev/urandom" >> /usr/lib/jvm/default-jvm/jre/lib/security/java.security \
 # 关闭安全套接字层SSL加密,防止与SQL_Server连接时报错
 && sed -i 's/^jdk.tls.disabledAlgorithms=SSLv3/#&/' /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/java.security

PS:增加 Win 宋体支持

FROM frolvlad/alpine-glibc:alpine-3.17_glibc-2.34

ARG JAVA_PACKAGE=8.372.07-r0

ENV JAVA_MAJOR_VERSION=8 \
    TZ=Asia/Shanghai \
    LANG='zh_CN.UTF-8' LANGUAGE='zh_CN:zh' LC_ALL='zh_CN.UTF-8'

COPY ./SimSun.ttf /usr/share/fonts/win/simsun.ttf    

RUN apk add --update tzdata curl openjdk8=${JAVA_PACKAGE} \
 && set -eux \
 && ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \
 && echo ${TZ} > /etc/timezone \
 && chmod 777 /usr/share/fonts/win/simsun.* \
 && fc-cache -fv \
 && rm -rf /var/cache/apk/* \
 && echo "securerandom.source=file:/dev/urandom" >> /usr/lib/jvm/default-jvm/jre/lib/security/java.security \
 && sed -i 's/^jdk.tls.disabledAlgorithms=SSLv3/#&/' /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/java.security
1
2
3
FROM openjdk8u372:alpine-3.17_glibc-2.34
ADD *.jar /app.jar
ENTRYPOINT ["sh","-c","java ${JAVA_OPTS} -jar /app.jar ${0} ${@}"]