我正在使用 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 中的內容,并且似乎正在作業

正如你所看到的,當我點擊保存時,這是控制臺中的輸出。

我已經檢查了容器內部,檔案是否已更新,并且它們已更新。所以我的問題是 - 為什么我的應用程式沒有使用新代碼更新,即使它說它已經更改并且檔案已更改?我的碼頭工人有事嗎?
uj5u.com熱心網友回復:
這最終成為我正在尋找的解決方案:
檔案
FROM eclipse-temurin:11
RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y inotify-tools dos2unix
ENV HOME=/app
RUN mkdir -p $HOME
WORKDIR $HOME
運行檔案
#!/bin/bash
dos2unix mvnw
./mvnw spring-boot:run -Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" &
while true; do
inotifywait -e modify,create,delete,move -r ./src/ && ./mvnw compile
done
docker-compose.yml
version: '3.3'
services:
api:
build:
context: ./
dockerfile: Dockerfile
volumes:
- ./:/app
- ./.m2:/root/.m2
working_dir: /app
command: sh run.sh
ports:
- 8080:8080
- 35729:35729
- 5005:5005
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/353066.html
