跟我学SpringCloud | 第十八篇:微服务 Docker 化之基础环境 (2)

代码清单:chapter17/dockerfiles/java9/Dockerfile
***

FROM registry.cn-shanghai.aliyuncs.com/weishiyao/alpine-3.10:glibc-2.30-r0 MAINTAINER inwsy@hotmail.com RUN echo -e "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.10/main\n\ https://mirror.tuna.tsinghua.edu.cn/alpine/v3.10/community" > /etc/apk/repositories RUN apk --update add curl bash openjdk9-jre && \ rm -rf /var/cache/apk/* ENV JAVA_HOME /usr/lib/jvm/default-jvm ENV PATH ${PATH}:${JAVA_HOME}/bin

OpenJDK 的 jre 这里笔者使用清华大学镜像站的镜像进行安装。

同样,此镜像作者已经上传阿里云镜像仓库,可以直接使用以下命令拉取:

docker pull registry.cn-shanghai.aliyuncs.com/springcloud-book/alpine3.10:openjdk9-jre-9.0.4

验证命令如下:

docker run --rm -it registry.cn-shanghai.aliyuncs.com/springcloud-book/alpine3.10:openjdk9-jre-9.0.4 java -version

执行结果如下:

openjdk version "9.0.4" OpenJDK Runtime Environment (build 9.0.4+12-alpine-r1) OpenJDK 64-Bit Server VM (build 9.0.4+12-alpine-r1, mixed mode) 3.4 Alpine + glibc + OpenJDK10

OpenJDK10 的镜像构建的 Dockerfile 如下:

代码清单:chapter17/dockerfiles/java10/Dockerfile
***

FROM registry.cn-shanghai.aliyuncs.com/weishiyao/alpine-3.10:glibc-2.30-r0 RUN echo -e "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.10/main\n\ https://mirror.tuna.tsinghua.edu.cn/alpine/v3.10/community" > /etc/apk/repositories RUN apk --update add curl bash openjdk10-jre && \ rm -rf /var/cache/apk/* ENV JAVA_HOME /usr/lib/jvm/default-jvm ENV PATH ${PATH}:${JAVA_HOME}/bin

同样,此镜像作者已经上传阿里云镜像仓库,可以直接使用以下命令拉取:

docker pull registry.cn-shanghai.aliyuncs.com/springcloud-book/alpine3.10:openjdk10-jre-10.0.2

验证命令如下:

docker run --rm -it registry.cn-shanghai.aliyuncs.com/springcloud-book/alpine3.10:openjdk10-jre-10.0.2 java -version

执行结果如下:

openjdk version "10.0.2" 2018-07-17 OpenJDK Runtime Environment (build 10.0.2+13-alpine-r0) OpenJDK 64-Bit Server VM (build 10.0.2+13-alpine-r0, mixed mode) 3.5 Alpine + glibc + OpenJDK11

OpenJDK11 的镜像构建的 Dockerfile 如下:

代码清单:chapter17/dockerfiles/java11/Dockerfile
***

FROM registry.cn-shanghai.aliyuncs.com/weishiyao/alpine-3.10:glibc-2.30-r0 MAINTAINER inwsy@hotmail.com RUN echo -e "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.10/main\n\ https://mirror.tuna.tsinghua.edu.cn/alpine/v3.10/community" > /etc/apk/repositories RUN apk --update add curl bash openjdk11-jre && \ rm -rf /var/cache/apk/* ENV JAVA_HOME /usr/lib/jvm/default-jvm ENV PATH ${PATH}:${JAVA_HOME}/bin

同样,此镜像作者已经上传阿里云镜像仓库,可以直接使用以下命令拉取:

docker pull registry.cn-shanghai.aliyuncs.com/springcloud-book/alpine3.10:openjdk11-jre-11.0.2

验证命令如下:

docker run --rm -it registry.cn-shanghai.aliyuncs.com/springcloud-book/alpine3.10:openjdk11-jre-11.0.2 java -version

执行结果如下:

openjdk version "11.0.4" 2019-07-16 OpenJDK Runtime Environment (build 11.0.4+4-alpine-r1) OpenJDK 64-Bit Server VM (build 11.0.4+4-alpine-r1, mixed mode) 4. 实例代码

示例代码-Github

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwddpy.html