构建Python2+Java8的 Docker 镜像
2020-07-09 本文已影响0人
cherishpf
基于Python2.7.15-alpine镜像来添加 Java8 环境
Dockerfile内容如下:
#
# 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
构建过程中遇到的问题:
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
根据以上信息可知,Dockerfile中设置的apk add --no-cache 'openjdk8=8.191.12-r0' 没有找到安装包,提示说可以使用openjdk8-8.242.08-r0这个版本。相应的也需要Dockerfile中ENV JAVA_VERSION 8u191设置为对应的版本ENV JAVA_VERSION 8u242。
2、网络问题
+ 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
根据以上信息可知,APKINDEX.tar.gz没有下载成功,不能继续执行命令,只能找个网络比较好的环境重试。
构建成功截图:
安装jre和jdk时比较慢镜像已上传到dockerhub,拉取命令:
docker pull cherishpf/python2-java8-alpine:1.0