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

基于官方Python3鏡像來添加Java8環(huán)境(參考官方Dockerfile)

Dockerfile內(nèi)容如下:

#
# NOTE: this docker file is used to build runtime environment.
# The project is a python app which contains a java jar lib.

FROM python:3
MAINTAINER yangpf <cherishpf@163.com>

# COPY ./requirements.txt /usr/local/src/requirements.txt

RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends \
        bzip2 \
        unzip \
        xz-utils \
        \
# utilities for keeping Debian and OpenJDK CA certificates in sync
        ca-certificates p11-kit \
#       \
# java.lang.UnsatisfiedLinkError: /usr/local/openjdk-11/lib/libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory
# java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager
# https://github.com/docker-library/openjdk/pull/235#issuecomment-424466077
        fontconfig libfreetype6 \
    ; \
    rm -rf /var/lib/apt/lists/*

# Default to UTF-8 file.encoding
ENV LANG C.UTF-8

ENV JAVA_HOME /usr/local/openjdk-8
ENV PATH $JAVA_HOME/bin:$PATH

# backwards compatibility shim
RUN { echo '#/bin/sh'; echo 'echo "$JAVA_HOME"'; } > /usr/local/bin/docker-java-home && chmod +x /usr/local/bin/docker-java-home && [ "$JAVA_HOME" = "$(docker-java-home)" ]

# https://adoptopenjdk.net/upstream.html
# >
# > What are these binaries?
# >
# > These binaries are built by Red Hat on their infrastructure on behalf of the OpenJDK jdk8u and jdk11u projects. The binaries are created from the unmodified source code at OpenJDK. Although no formal support agreement is provided, please report any bugs you may find to https://bugs.java.com/.
# >
ENV JAVA_VERSION 8u252
ENV JAVA_BASE_URL https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/download/jdk8u252-b09/OpenJDK8U-jre_
ENV JAVA_URL_VERSION 8u252b09
# https://github.com/docker-library/openjdk/issues/320#issuecomment-494050246
# >
# > I am the OpenJDK 8 and 11 Updates OpenJDK project lead.
# > ...
# > While it is true that the OpenJDK Governing Board has not sanctioned those releases, they (or rather we, since I am a member) didn't sanction Oracle's OpenJDK releases either. As far as I am aware, the lead of an OpenJDK project is entitled to release binary builds, and there is clearly a need for them.
# >

RUN set -eux; \
    \
    dpkgArch="$(dpkg --print-architecture)"; \
    case "$dpkgArch" in \
        amd64) upstreamArch='x64' ;; \
        arm64) upstreamArch='aarch64' ;; \
        *) echo >&2 "error: unsupported architecture: $dpkgArch" ;; \
    esac; \
    \
    wget -O openjdk.tgz.asc "${JAVA_BASE_URL}${upstreamArch}_linux_${JAVA_URL_VERSION}.tar.gz.sign"; \
    wget -O openjdk.tgz "${JAVA_BASE_URL}${upstreamArch}_linux_${JAVA_URL_VERSION}.tar.gz" --progress=dot:giga; \
    \
    export GNUPGHOME="$(mktemp -d)"; \
# TODO find a good link for users to verify this key is right (https://mail.openjdk.java.net/pipermail/jdk-updates-dev/2019-April/000951.html is one of the only mentions of it I can find); perhaps a note added to https://adoptopenjdk.net/upstream.html would make sense?
# no-self-sigs-only: https://salsa.debian.org/debian/gnupg2/commit/c93ca04a53569916308b369c8b218dad5ae8fe07
    gpg --batch --keyserver ha.pool.sks-keyservers.net --keyserver-options no-self-sigs-only --recv-keys CA5F11C6CE22644D42C6AC4492EF8D39DC13168F; \
# also verify that key was signed by Andrew Haley (the OpenJDK 8 and 11 Updates OpenJDK project lead)
# (https://github.com/docker-library/openjdk/pull/322#discussion_r286839190)
    gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys EAC843EBD3EFDB98CC772FADA5CD6035332FA671; \
    gpg --batch --list-sigs --keyid-format 0xLONG CA5F11C6CE22644D42C6AC4492EF8D39DC13168F \
        | tee /dev/stderr \
        | grep '0xA5CD6035332FA671' \
        | grep 'Andrew Haley'; \
    gpg --batch --verify openjdk.tgz.asc openjdk.tgz; \
    gpgconf --kill all; \
    rm -rf "$GNUPGHOME"; \
    \
    mkdir -p "$JAVA_HOME"; \
    tar --extract \
        --file openjdk.tgz \
        --directory "$JAVA_HOME" \
        --strip-components 1 \
        --no-same-owner \
    ; \
    rm openjdk.tgz*; \
    \
# TODO strip "demo" and "man" folders?
    \
# update "cacerts" bundle to use Debian's CA certificates (and make sure it stays up-to-date with changes to Debian's store)
# see https://github.com/docker-library/openjdk/issues/327
#     http://rabexc.org/posts/certificates-not-working-java#comment-4099504075
#     https://salsa.debian.org/java-team/ca-certificates-java/blob/3e51a84e9104823319abeb31f880580e46f45a98/debian/jks-keystore.hook.in
#     https://git.alpinelinux.org/aports/tree/community/java-cacerts/APKBUILD?id=761af65f38b4570093461e6546dcf6b179d2b624#n29
    { \
        echo '#!/usr/bin/env bash'; \
        echo 'set -Eeuo pipefail'; \
        echo 'if ! [ -d "$JAVA_HOME" ]; then echo >&2 "error: missing JAVA_HOME environment variable"; exit 1; fi'; \
# 8-jdk uses "$JAVA_HOME/jre/lib/security/cacerts" and 8-jre and 11+ uses "$JAVA_HOME/lib/security/cacerts" directly (no "jre" directory)
        echo 'cacertsFile=; for f in "$JAVA_HOME/lib/security/cacerts" "$JAVA_HOME/jre/lib/security/cacerts"; do if [ -e "$f" ]; then cacertsFile="$f"; break; fi; done'; \
        echo 'if [ -z "$cacertsFile" ] || ! [ -f "$cacertsFile" ]; then echo >&2 "error: failed to find cacerts file in $JAVA_HOME"; exit 1; fi'; \
        echo 'trust extract --overwrite --format=java-cacerts --filter=ca-anchors --purpose=server-auth "$cacertsFile"'; \
    } > /etc/ca-certificates/update.d/docker-openjdk; \
    chmod +x /etc/ca-certificates/update.d/docker-openjdk; \
    /etc/ca-certificates/update.d/docker-openjdk; \
    \
# https://github.com/docker-library/openjdk/issues/331#issuecomment-498834472
    find "$JAVA_HOME/lib" -name '*.so' -exec dirname '{}' ';' | sort -u > /etc/ld.so.conf.d/docker-openjdk.conf; \
    ldconfig; \
    \
# basic smoke test
    java -version
    
# RUN pip install --no-cache-dir -r /usr/local/src/requirements.txt  -i https://pypi.tuna.tsinghua.edu.cn/simple

# 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)建過程中遇到的問題:
下載失敗(網(wǎng)絡(luò)問題導(dǎo)致)
Errors during downloading metadata for repository 'base':
 - Curl error (6): Couldn't resolve host name for http://mirrors.cloud.aliyuncs.com/centos/8/os/x86_64/repodata/repomd.xml [Could not resolve host: mirrors.cloud.aliyuncs.com]
 - Curl error (28): Timeout was reached for http://mirrors.aliyuncs.com/centos/8/os/x86_64/repodata/repomd.xml [Connection timed out after 30003 milliseconds]
 - Status code: 404 for http://mirrors.aliyun.com/centos/8/os/x86_64/repodata/repomd.xml (IP: 219.238.20.87)
CentOS-8 - Base - mirrors.aliyun.com 80 B/s | 2.5 kB 00:31 
Error: Failed to download metadata for repo 'base': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
+ wget -O openjdk.tgz.asc https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/download/jdk8u252-b09/OpenJDK8U-jre_aarch64_linux_8u252b09.tar.gz.sign
--2020-07-09 08:38:05-- https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/download/jdk8u252-b09/OpenJDK8U-jre_aarch64_linux_8u252b09.tar.gz.sign
Resolving github.com (github.com)... 52.74.223.119
Connecting to github.com (github.com)|52.74.223.119|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2020-07-09 08:38:06 ERROR 404: Not Found.

The command '/bin/sh -c set -eux; dpkgArch="$(dpkg --print-architecture)"; case "$dpkgArch" in amd64) upstreamArch='x64' ;; arm64) upstreamArch='aarch64' ;; *) echo >&2 "error: unsupported architecture: $dpkgArch" ;; esac;
Saving to: ‘openjdk.tgz’

0K ........ ........ ........ . 65% 103K=4m8s

2020-07-09 03:38:29 (103 KB/s) - Read error at byte 26233397/40097077 (Error in the pull function.). Retrying.

--2020-07-09 03:38:30-- (try: 2) https://github-production-release-asset-2e65be.s3.amazonaws.com/177164113/e847a580-7ea3-11ea-9384-66e465e55281?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20200709%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200709T032918Z&X-Amz-Expires=300&X-Amz-Signature=8bd859665240280a28c00d6fc517d380e50f0fae6821f6a592d1afa4ef6d3823&X-Amz-SignedHeaders=host&actor_id=0&repo_id=177164113&response-content-disposition=attachment%3B%20filename%3DOpenJDK8U-jre_x64_linux_8u252b09.tar.gz&response-content-type=application%2Foctet-stream
Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|52.217.100.204|:443... connected.
HTTP request sent, awaiting response... 403 Forbidden
2020-07-09 03:38:31 ERROR 403: Forbidden.
Saving to: ‘openjdk.tgz’

0K ........ ........ ........ ........ 83% 141K 45s
 32768K ...... 100% 59.1K=5m41s

2020-07-09 12:15:53 (115 KB/s) - ‘openjdk.tgz’ saved [40097077/40097077]

+ mktemp -d
+ export GNUPGHOME=/tmp/tmp.VA3iB01iUY
+ gpg --batch --keyserver ha.pool.sks-keyservers.net --keyserver-options no-self-sigs-only --recv-keys CA5F11C6CE22644D42C6AC4492EF8D39DC13168F
gpg: keybox '/tmp/tmp.VA3iB01iUY/pubring.kbx' created
構(gòu)建成功提示:
+ /etc/ca-certificates/update.d/docker-openjdk
+ find /usr/local/openjdk-8/lib -name *.so -exec dirname {} ;
+ sort -u
+ ldconfig
+ java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
 ---> cbdae72b3264
Removing intermediate container 2edfd928cd45
Successfully built cbdae72b3264
拉取該鏡像(1.04 GB)

docker pull cherishpf/python3-java8:1.0

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末轻掩,一起剝皮案震驚了整個濱河市屡贺,隨后出現(xiàn)的幾起案子袱耽,更是在濱河造成了極大的恐慌,老刑警劉巖欣孤,帶你破解...
    沈念sama閱讀 211,884評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件凯旋,死亡現(xiàn)場離奇詭異,居然都是意外死亡钉迷,警方通過查閱死者的電腦和手機至非,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,347評論 3 385
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來糠聪,“玉大人荒椭,你說我怎么就攤上這事〗Ⅲ。” “怎么了趣惠?”我有些...
    開封第一講書人閱讀 157,435評論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長身害。 經(jīng)常有香客問我味悄,道長,這世上最難降的妖魔是什么塌鸯? 我笑而不...
    開封第一講書人閱讀 56,509評論 1 284
  • 正文 為了忘掉前任侍瑟,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘涨颜。我一直安慰自己费韭,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 65,611評論 6 386
  • 文/花漫 我一把揭開白布庭瑰。 她就那樣靜靜地躺著星持,像睡著了一般。 火紅的嫁衣襯著肌膚如雪弹灭。 梳的紋絲不亂的頭發(fā)上督暂,一...
    開封第一講書人閱讀 49,837評論 1 290
  • 那天,我揣著相機與錄音鲤屡,去河邊找鬼损痰。 笑死,一個胖子當(dāng)著我的面吹牛酒来,可吹牛的內(nèi)容都是我干的卢未。 我是一名探鬼主播,決...
    沈念sama閱讀 38,987評論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼堰汉,長吁一口氣:“原來是場噩夢啊……” “哼辽社!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起翘鸭,我...
    開封第一講書人閱讀 37,730評論 0 267
  • 序言:老撾萬榮一對情侶失蹤滴铅,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后就乓,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體汉匙,經(jīng)...
    沈念sama閱讀 44,194評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,525評論 2 327
  • 正文 我和宋清朗相戀三年生蚁,在試婚紗的時候發(fā)現(xiàn)自己被綠了噩翠。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,664評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡邦投,死狀恐怖伤锚,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情志衣,我是刑警寧澤屯援,帶...
    沈念sama閱讀 34,334評論 4 330
  • 正文 年R本政府宣布,位于F島的核電站念脯,受9級特大地震影響狞洋,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜和二,卻給世界環(huán)境...
    茶點故事閱讀 39,944評論 3 313
  • 文/蒙蒙 一徘铝、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦惕它、人聲如沸怕午。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,764評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽郁惜。三九已至,卻和暖如春甲锡,著一層夾襖步出監(jiān)牢的瞬間兆蕉,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,997評論 1 266
  • 我被黑心中介騙來泰國打工缤沦, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留虎韵,地道東北人。 一個月前我還...
    沈念sama閱讀 46,389評論 2 360
  • 正文 我出身青樓缸废,卻偏偏與公主長得像包蓝,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子企量,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,554評論 2 349