docker - 如何在 Docker 中使用 java 11?
问题描述
在我的 DockerFile 中,我的 FROM 行如下:
FROM openjdk:11-jdk-alpine 作为构建
以前它在 java 8 上,一切正常。
现在我得到这个错误:
C:\dev\shape-shop-back-end>docker build .
[+] Building 2.0s (5/5) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 1.31kB 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> CANCELED [internal] load metadata for docker.io/library/openjdk:11-jre-alpine 1.8s
=> ERROR [internal] load metadata for docker.io/library/openjdk:11-jdk-alpine 1.8s
=> [auth] library/openjdk:pull token for registry-1.docker.io 0.0s
------
> [internal] load metadata for docker.io/library/openjdk:11-jdk-alpine:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: docker.io/library/openjdk:11-jdk-alpine: not found
我的码头文件:
#### Stage 1: Build the application
FROM openjdk:11-jdk-alpine as build
# Set the current working directory inside the image
WORKDIR /app
# Copy maven executable to the image
COPY mvnw .
COPY .mvn .mvn
# Copy the pom.xml file
COPY pom.xml .
# Build all the dependencies in preparation to go offline.
# This is a separate step so the dependencies will be cached unless
# the pom.xml file has changed.
RUN ./mvnw dependency:go-offline -B
# Copy the project source
COPY src src
# Package the application
RUN ./mvnw package -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)
#### Stage 2: A minimal docker image with command to run the app
FROM openjdk:11-jre-alpine
ARG DEPENDENCY=/app/target/dependency
# Copy project dependencies from the build stage
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","com.shapeshop.App"]
#ARG JAR_FILE=target/*.jar
#COPY ${JAR_FILE} app.jar
#ENTRYPOINT ["java","-jar","/app.jar"]
#
## Expose port 80 to the Docker host, so we can access it
## from the outside.
#EXPOSE 8080
我错过了什么吗?
解决方案
这可能会有所帮助: https ://hub.docker.com/_/openjdk
“Alpine 的 OpenJDK 端口不在 OpenJDK 支持的版本中,因为它不在主线代码库中。它仅作为 OpenJDK Project Portola 的早期访问版本提供。另请参阅此评论。因此,此图像遵循可用的内容来自 OpenJDK 项目的维护者。
这意味着基于 Alpine 的映像仅针对 OpenJDK 的早期访问版本发布。一旦特定版本成为“通用”版本,Alpine 版本就会从“支持的标签”中删除;它们仍然可以拉取,但将不再更新。”
我不使用 java 图像,这可能就足够了: https ://hub.docker.com/r/adoptopenjdk/openjdk11/
推荐阅读
- sql - 如何在一张空表中使用三重 INNER JOIN?
- enums - SystemVerilog - 如何在编译时获取枚举类型的数量
- java - 如何在 OnBackPressed 上显示自定义对话框
- java - 尝试使用不是实体的对象创建 SpringFramework Bean 时出现“IllegalArgumentException:不是托管类型”
- python - pytesseract 无法识别数字 77
- python - 在 discord.py 中显示其他命令对该命令的输入
- mysql - 以声明方式将 SQL 模式应用于表的最简单方法?
- html - 无法在烧瓶中返回 html 页面
- amazon-web-services - AWS API Gateway 与 SNS 集成的工作示例,包括 MessageAttributes
- vim - 跳转到包含文本的下一行(vim)