構(gòu)建Python2+Java8的 Docker 鏡像

基于Python2.7.15-alpine鏡像來添加 Java8 環(huán)境

Dockerfile內(nèi)容如下:

#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#

FROM python:2.7.15-alpine

# A few reasons for installing distribution-provided OpenJDK:
#
# 1. Oracle. Licensing prevents us from redistributing the official JDK.
#
# 2. Compiling OpenJDK also requires the JDK to be installed, and it gets
# really hairy.
#
# For some sample build times, see Debian's buildd logs:
# https://buildd.debian.org/status/logs.php?pkg=openjdk-8
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8
# add a simple script that can auto-detect the appropriate JAVA_HOME value
# based on whether the JDK or only the JRE is installed
RUN { \
        echo '#!/bin/sh'; \
        echo 'set -e'; \
        echo; \
        echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
    } > /usr/local/bin/docker-java-home \
    && chmod +x /usr/local/bin/docker-java-home
ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
ENV JAVA_VERSION 8u242
ENV JAVA_ALPINE_VERSION 8.242.08-r0
RUN set -x \
    && apk add --no-cache \
        openjdk8="$JAVA_ALPINE_VERSION" \
    && [ "$JAVA_HOME" = "$(docker-java-home)" ]
# If you're reading this and have any feedback on how this image could be
# improved, please open an issue or a pull request so we can discuss it!
#
# https://github.com/docker-library/openjdk/issues
構(gòu)建過程中遇到的問題:
1、jdk安裝包問題
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/aarch64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/aarch64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  openjdk8-8.242.08-r0:
    breaks: world[openjdk8=8.191.12-r0]
The command '/bin/sh -c set -x     && apk add --no-cache         openjdk8="$JAVA_ALPINE_VERSION"     && [ "$JAVA_HOME" = "$(docker-java-home)" ]' returned a non-zero code: 1

根據(jù)以上信息可知,Dockerfile中設(shè)置的apk add --no-cache 'openjdk8=8.191.12-r0' 沒有找到安裝包,提示說可以使用openjdk8-8.242.08-r0這個版本。相應(yīng)的也需要Dockerfile中ENV JAVA_VERSION 8u191設(shè)置為對應(yīng)的版本ENV JAVA_VERSION 8u242。

2、網(wǎng)絡(luò)問題
+ apk add --no-cache 'openjdk8=8.242.08-r0'
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz: temporary error (try again later)
  openjdk8 (missing):
    required by: world[openjdk8=8.242.08-r0]
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz: temporary error (try again later)
ERROR: unsatisfiable constraints:
The command '/bin/sh -c set -x     && apk add --no-cache         openjdk8="$JAVA_ALPINE_VERSION"     && [ "$JAVA_HOME" = "$(docker-java-home)" ]' returned a non-zero code: 1

根據(jù)以上信息可知,APKINDEX.tar.gz沒有下載成功,不能繼續(xù)執(zhí)行命令,只能找個網(wǎng)絡(luò)比較好的環(huán)境重試。

構(gòu)建成功截圖:

安裝jre和jdk時比較慢

鏡像已上傳到dockerhub,拉取命令:
docker pull cherishpf/python2-java8-alpine:1.0

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容