简体   繁体   English

Dockerfile 高山图像 apk 找不到 Java 8

[英]Dockerfile alpine image apk cannot find Java 8

I wanted to reduce my docker image and switched to an alpine base image instead.我想减少我的 docker 镜像并切换到 alpine 基础镜像。 This lead to problems bash not finding apt.这会导致 bash 找不到 apt 的问题。 Turns out, I have to use apk instead.事实证明,我必须改用 apk。 However, it does not seem to find the java version I need.但是,它似乎没有找到我需要的 java 版本。 Here is my dockerfile这是我的 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

I have also tried我也试过

RUN apk update && apk add -t jessie-backports openjdk-8-jre-headless ca-certificates-java && rm -rf /var/lib/apt/lists/*

According to https://unix.stackexchange.com/questions/342403/openjdk-8-jre-headless-depends-ca-certificates-java-but-it-is-not-going-to-be but that also fails, not sure if the -t flags fault:根据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 

Alpine uses entirely different package repositories than Debian or Ubuntu. Alpine 使用与 Debian 或 Ubuntu 完全不同的软件包存储库。 The package openjdk-8-jre-headless doesn't exist there.那里不存在openjdk-8-jre-headless包。 You can check this here and find the correct package that fits your needs.您可以在此处查看并找到适合您需求的正确包装。

You can check how the official alpine OpenJDK image downloads java and follow the same steps你可以查看官方的 alpine OpenJDK 镜像是如何下载 java 并按照相同的步骤操作的

check Dockerfile检查Dockerfile

In short, you can add the following code in your Dockerfile总之,你可以在你的 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)" ]

I hope this helps我希望这有帮助

如果您使用的是 Alpine 图像,则使用以下命令添加 java8

RUN apk add openjdk8-jre

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker alpine + oracle java:找不到java - Docker alpine + oracle java: cannot find java Docker alpine apk 找不到 git-lfs package - Docker alpine apk cannot find git-lfs package Docker 图片 高山 java 8? - Docker image alpine java 8? apk python 软件包未安装在 Alpine Docker 图像中 - apk python packages not installing in Alpine Docker Image 为什么我们需要在 Dockerfile 中有一个 Alpine 或 Ubuntu 基础镜像? - Why do we need to have an Alpine or Ubuntu Base Image in the Dockerfile? Dockerfile:如何在节点高山映像上正确安装 bcrypt? - Dockerfile: How to install bcrypt correctly on a node alpine image? Dockerfile:将在超薄基础映像中构建的依赖项复制到 alpine - Dockerfile: Copy dependencies builded in slim base image to alpine 在 python 高山映像的 Dockerfile 中安装 pandas 和 pycryptodome 依赖项 - Installing pandas and pycryptodome dependencies in Dockerfile for python alpine image --no-cache 与 rm /var/cache/apk/* 相比,Alpine Dockerfile 的优势 - Alpine Dockerfile advantages of --no-cache vs. rm /var/cache/apk/* 在新推送的 docker 镜像 ruby​​:2.7.4-alpine3.13 上安装一些 ruby​​gems 时“找不到 -lucontext” - "cannot find -lucontext" when installing some rubygems on newly pushed docker image ruby:2.7.4-alpine3.13
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM