【发布时间】:2021-12-20 05:20:06
【问题描述】:
我正在使用 Spring boot,并且我正在尝试设置一个更新应用程序的 docker 环境,当我在自己的计算机上进行更改时。
我发现我需要使用 Spring Boot 开发工具,并且我已经设置了它。但是即使我点击保存并且可以在控制台中看到它更新了,应用程序也不会更新代码。
这是我的 Dockerfile:
#### Stage 1: Build the application
FROM openjdk:8-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:8-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.example.polls.PollsApplication"]
这就是我的 POM.xml 中的内容,并且似乎正在工作
如您所见,当我点击保存时,这是控制台中的输出。
我检查了容器内部的文件是否已更新,并且确实如此。 所以我的问题是 - 为什么我的应用程序没有用新代码更新,即使它说它已经改变并且文件已经改变?是不是我的 docker 有问题?
【问题讨论】:
-
那个Dockerfile不能用作实时重载环境;它不包括任何原始 Java 源文件、它们的 PNG 渲染或 JDK。我建议在这里使用普通的非 Docker Java 开发环境。
标签: java spring spring-boot docker