[英]I made a change to my Dockerfile, but my “docker build” isn't reflecting the change
I'm learning how to use docker, this docker image is being built with a Spring Boot REST API that was running fully local.
我的第一个 docker 图像如下
FROM amazoncorretto:11-alpine-jdk as build
WORKDIR /workspace/app
COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
COPY src src
RUN ./mvnw install -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)
FROM amazoncorretto:11-alpine-jdk
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","com.helloyou.demo.DemoApplication"]
当我第一次运行命令docker build -t myapp.
我得到了这个结果
jamal@DESKTOP-64JJ5P8:~/dev/hello-you-endpoint$ docker build -t fer2ap/app .
[+] Building 7.5s (9/9) FINISHED
=> [internal] load build definition from Dockerfile 2.2s
=> => transferring dockerfile: 38B 0.0s
=> [internal] load .dockerignore 3.1s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/amazoncorretto:11-alpine-jdk 1.9s
=> [stage-1 1/5] FROM docker.io/library/amazoncorretto:11-alpine-jdk@sha256:76acd2ab267cb71abeab875af97d91fb483d81bc4e372d1dd28ba 0.0s
=> [internal] load build context 1.4s
=> => transferring context: 2B 0.0s
=> CACHED [stage-1 2/5] RUN addgroup -S spring && adduser -S spring -G spring 0.0s
=> ERROR [stage-1 3/5] COPY /workspace/app/target/dependency/BOOT-INF/lib /app/lib 0.0s
=> ERROR [stage-1 4/5] COPY /workspace/app/target/dependency/META-INF /app/META-INF 0.0s
=> ERROR [stage-1 5/5] COPY /workspace/app/target/dependency/BOOT-INF/classes /app 0.0s
------
> [stage-1 3/5] COPY /workspace/app/target/dependency/BOOT-INF/lib /app/lib:
------
------
> [stage-1 4/5] COPY /workspace/app/target/dependency/META-INF /app/META-INF:
------
------
> [stage-1 5/5] COPY /workspace/app/target/dependency/BOOT-INF/classes /app:
------
failed to compute cache key: "/workspace/app/target/dependency/BOOT-INF/classes" not found: not found
起初我认为这是WORKDIR
和ARG DEPENDENCY
的错误。 所以我对其进行了更改,以匹配我的项目的绝对路径~/dev/hello-you-endpoint
。 改后的Dockerfile是这样的
FROM amazoncorretto:11-alpine-jdk as build
WORKDIR dev/hello-you-endpoint
COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
COPY src src
RUN ./mvnw install
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)
FROM amazoncorretto:11-alpine-jdk
VOLUME /tmp
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ARG DEPENDENCY=dev/hello-you-endpoint/target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","com.helloyou.demo.DemoApplication"]
当我运行docker build -t myapp.
我得到了相同的 output failed to compute cache key: "/workspace/app/target/dependency/BOOT-INF/lib" not found: not found
。
jamal@DESKTOP-64JJ5P8:~/dev/hello-you-endpoint$ docker build -t fer2ap/app .
[+] Building 8.6s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 3.3s
=> => transferring dockerfile: 38B 0.0s
=> [internal] load .dockerignore 2.1s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/amazoncorretto:11-alpine-jdk 3.2s
=> [auth] library/amazoncorretto:pull token for registry-1.docker.io 0.0s
=> [internal] load build context 1.4s
=> => transferring context: 2B 0.0s
=> [stage-1 1/5] FROM docker.io/library/amazoncorretto:11-alpine-jdk@sha256:76acd2ab267cb71abeab875af97d91fb483d81bc4e372d1dd28ba 0.0s
=> CACHED [stage-1 2/5] RUN addgroup -S spring && adduser -S spring -G spring 0.0s
=> ERROR [stage-1 3/5] COPY /workspace/app/target/dependency/BOOT-INF/lib /app/lib 0.0s
=> ERROR [stage-1 4/5] COPY /workspace/app/target/dependency/META-INF /app/META-INF 0.0s
=> ERROR [stage-1 5/5] COPY /workspace/app/target/dependency/BOOT-INF/classes /app 0.0s
------
> [stage-1 3/5] COPY /workspace/app/target/dependency/BOOT-INF/lib /app/lib:
------
------
> [stage-1 4/5] COPY /workspace/app/target/dependency/META-INF /app/META-INF:
------
------
> [stage-1 5/5] COPY /workspace/app/target/dependency/BOOT-INF/classes /app:
------
failed to compute cache key: "/workspace/app/target/dependency/BOOT-INF/lib" not found: not found
我认为收到同样的错误很奇怪,所以我一直试图找出问题所在。 我删除了我的 Dockerfile 中的所有内容,我得到了同样的错误failed to compute cache key: "/workspace/app/target/dependency/BOOT-INF/classes" not found: not found
。
在写这个问题之前,我发现了一些类似的案例( 我的 dockerfile 的更改在运行 `docker build` 时没有反映出来)但是他们的解决方案都不适合我。 我做了一些研究,对 docker 缓存有所了解,但docker build --no-cache -t myapp.
也没有用。
在尝试使用多层支持构建映像之前,我使用 docker 教程( https://spring-io/spring-guides/gs )进行了第一次 spring 引导在入门教程结束时,我有以下 Dockerfile。 我尝试用它构建我的图像,但它现在也无法正常工作,当使用这个 Dockerfile 时,我得到与上述相同的错误, failed to compute cache key: "/workspace/app/target/dependency/BOOT-INF/lib" not found: not found
。
FROM amazoncorretto:11-alpine-jdk
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","com.helloyou.demo.DemoApplication"]
文件结构:我的 Dockerfile、mvnw、pom.xml 和我的应用程序的源文件夹位于 /home/jamal/dev/hello-you-endpoint/
你可以构建你的 dockerfile 作为这个例子
FROM golang AS build-stage
RUN go get -u github.com/LK4D4/vndr
FROM scratch AS export-stage
COPY --from=build-stage /go/bin/vndr /
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.