我尝试在我的 spring boot 中运行 docker,当我在目录 booting-web/ 中添加 Dockerfile 并输入一些如下代码时:
FROM maven:3.6.3-openjdk-17-slim as BUILDER
ARG VERSION=0.0.1-SNAPSHOT
WORKDIR /build/
COPY pom.xml /build/
COPY src /build/src/
RUN mvn clean package
COPY target/booting-web-${VERSION}.jar target/application.jar
FROM openjdk:17-oracle
WORKDIR /app/
COPY --from=BUILDER /build/target/application.jar /app/
CMD java -jar /app/application.jar
之后,我保存了 docker 文件,然后打开终端,输入sudo docker build -t booting-web .
以下内容,然后收到如下错误:
=> [internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 386B 0.0s
=> [internal] load metadata for docker.io/library/openjdk:17-oracle 1.0s
=> [internal] load metadata for docker.io/library/maven:3.6.3-openjdk-17-slim 0.9s
=> CANCELED [builder 1/6] FROM docker.io/library/maven:3.6.3-openjdk-17-slim@sha256:6d8d6569d5a3b81e033e2f9905290fbd9c9b509f 0.3s
=> => resolve docker.io/library/maven:3.6.3-openjdk-17-slim@sha256:6d8d6569d5a3b81e033e2f9905290fbd9c9b509fce1889cdea5692b00 0.1s
=> => sha256:6d8d6569d5a3b81e033e2f9905290fbd9c9b509fce1889cdea5692b003edc9bb 549B / 549B 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 868B 0.0s
=> CANCELED [stage-1 1/3] FROM docker.io/library/openjdk:17-oracle@sha256:83ffa182a7cfc8313583fe1cc42172a48a021f368a1ff11fe0 0.4s
=> => resolve docker.io/library/openjdk:17-oracle@sha256:83ffa182a7cfc8313583fe1cc42172a48a021f368a1ff11fe0d957c3b3b8a620 0.1s
=> => sha256:83ffa182a7cfc8313583fe1cc42172a48a021f368a1ff11fe0d957c3b3b8a620 547B / 547B 0.0s
=> => sha256:98f0304b3a3b7c12ce641177a99d1f3be56f532473a528fda38d53d519cafb13 954B / 954B 0.0s
=> => sha256:5e28ba2b4cdb3a7c3bd0ee2e635a5f6481682b77eabf8b51a17ea8bfe1c05697 4.45kB / 4.45kB 0.0s
=> CACHED [builder 2/6] WORKDIR /build/ 0.0s
=> CACHED [builder 3/6] COPY pom.xml /build/ 0.0s
=> CACHED [builder 4/6] COPY src /build/src/ 0.0s
=> CACHED [builder 5/6] RUN mvn clean package 0.0s
=> ERROR [builder 6/6] COPY target/Booting-web-0.0.1-SNAPSHOT.jar target/application.jar 0.0s
------
> [builder 6/6] COPY target/Booting-web-0.0.1-SNAPSHOT.jar target/application.jar:
------
Dockerfile:8
--------------------
6 |
7 | RUN mvn clean package
8 | >>> COPY target/Booting-web-${VERSION}.jar target/application.jar
9 |
10 |
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 269de514-ac0b-4686-9da1-3bee7003c2b0::hwlt7penrckamosf5gw598w51: "/target/Booting-web-0.0.1-SNAPSHOT.jar": not found
我一直尝试从这里更改 jdk 版本:
FROM openjdk:17.0.8.1-jre-slim
WORKDIR /app/
进入这个:
FROM openjdk:17-oracle
WORKDIR /app/
但这样不行。有什么办法吗?