【发布时间】:2020-01-13 08:48:57
【问题描述】:
我在 spring-boot+ mysql+ react js 应用程序上遇到了一个问题,该应用程序可以正常工作。(我在尝试将它部署到 docker 之前已经对其进行了测试)。
当我发出命令“docker-compose up -d”时,它可以工作,我可以看到容器,我可以访问前端,但后端/服务器中的任何请求都被拒绝。
我查看了服务器日志并得到错误:Error: Could not find or load main class com.example.springdemo.SpringDemoApplication
我的码头文件:
#### 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.springdemo.SpringDemoApplication"]
我检查了一下,主目录的路径是正确的。我不知道为什么它找不到主类。
后端代码位于:https://github.com/Diana-Ioana/docker_app,以及 docker-compose.yml 文件和后端的 Dockerfile。 我使用 docker 工具箱(不是 docker 桌面,我有 WIN 10 HOME)
【问题讨论】:
-
这可能很愚蠢,但您不会忘记在这一行添加一个斜线:“COPY src src”吗?另外,如果你注释掉 dockerfile 的最后一行并用存根替换它,然后 shell 进入容器并手动运行命令,会发生什么?我遇到过类似的问题,我的代码没有到位但也没有失败。
-
在您的最后阶段,没有任何未注释的
COPY行,因此您正在运行未修改的 JRE 映像。您实际上是COPY构建映像中的构建jar 文件还是类文件?同样,您是否真的构建了应用程序(您已将RUN ./mvnw package注释掉)? -
Dockerfile 是在为 .mvn 运行
mvn -N io.takari:maven:wrapper时自动生成的,所以我想象它应该是这样的,我没有修改任何东西。
标签: java spring-boot maven docker