我想减少我的docker映像,而改用高山基础映像。这导致bash无法找到合适的问题。原来,我必须改用apk。但是,它似乎找不到我需要的Java版本。这是我的dockerfile
#Use alpine golang
FROM golang:alpine
#Get the code from local code commit repo
WORKDIR /go/src/xxx
COPY . /go/src/xxx
#Install Java and cleanup after in the same layer
RUN apk update && apk add openjdk-8-jre-headless && rm -rf /var/lib/apt/lists/*
#Install dependencies recursively and remove the third_party directory after it has been used for compiling.
RUN go get ./... && go run setup.go && RUN rm -rf third_party
#More commands...
---> 32a6b6b5f196
Step 4/8 : RUN apk update && apk add openjdk-8-jre-headless && rm -rf /var/lib/apt/lists/*
---> Running in bc48930e48be
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
v3.9.4-4-gd5dd5c1cd0 [http://dl-cdn.alpinelinux.org/alpine/v3.9/main]
v3.9.4-5-gcfdf5452f1 [http://dl-cdn.alpinelinux.org/alpine/v3.9/community]
OK: 9766 distinct packages available
openjdk-8-jre-headless (missing):
·[91mERROR: unsatisfiable constraints:
·[0m required by: world[openjdk-8-jre-headless]
The command '/bin/sh -c apk update && apk add openjdk-8-jre-headless && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 1
我也尝试过
RUN apk update && apk add -t jessie-backports openjdk-8-jre-headless ca-certificates-java && rm -rf /var/lib/apt/lists/*
根据https://unix.stackexchange.com/questions/342403/openjdk-8-jre-headless-depends-ca-certificates-java-but-it-is-not-going-to-be,但这也失败了,不确定-t标志是否出错:
Step 4/7 : RUN apk update && apk add -t jessie-backports openjdk-8-jre-headless ca-certificates-java && rm -rf /var/lib/apt/lists/*
---> Running in 1e2ef22e7c16
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
v3.9.4-4-gd5dd5c1cd0 [http://dl-cdn.alpinelinux.org/alpine/v3.9/main]
v3.9.4-5-gcfdf5452f1 [http://dl-cdn.alpinelinux.org/alpine/v3.9/community]
OK: 9766 distinct packages available
·[91mERROR: unsatisfiable constraints:
·[0m openjdk-8-jre-headless (missing):
required by: jessie-backports-0[openjdk-8-jre-headless]
ca-certificates-java (missing):
required by: jessie-backports-0[ca-certificates-java]
The command '/bin/sh -c apk update && apk add -t jessie-backports openjdk-8-jre-headless ca-certificates-java && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 3
答案 0 :(得分:1)
Alpine使用的软件包存储库与Debian或Ubuntu完全不同。软件包openjdk-8-jre-headless
在那里不存在。您可以检查此here并找到适合您需求的正确包装。
答案 1 :(得分:1)
您可以检查官方高山OpenJDK映像如何下载Java并遵循相同的步骤
简而言之,您可以在Dockerfile中添加以下代码
# 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 8u212
ENV JAVA_ALPINE_VERSION 8.212.04-r0
RUN set -x \
&& apk add --no-cache \
openjdk8="$JAVA_ALPINE_VERSION" \
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
我希望这对您有帮助
答案 2 :(得分:1)
如果您使用的是 Alpine 映像,请使用以下命令添加 java8
RUN apk add openjdk8-jre