gpt4 book ai didi

spring-boot - 无法对 spring 微服务多模块应用程序进行 dockerize

转载 作者:行者123 更新时间:2023-12-02 20:41:37 24 4
gpt4 key购买 nike

我正在使用 JAVA 11、maven、spring 构建应用程序。
它有一个根 pom 来组织所有子模块,如下所示:
https://github.com/erickmob/spring-petclinic-microservices
这是项目结构:
project structure
我试图在根项目上创建这个 docker-compose.yml:

  version: '2'
services:
config-server:
build:
context: ./config-server
dockerfile: Dockerfile
image: config-server
container_name: config-server
mem_limit: 512M
ports:
- 8888:8888
在 config-server 这个 dockerfile 中:
FROM maven:3.6.3-adoptopenjdk-11 as build

WORKDIR /usr/src/config-server/
COPY . /usr/src/config-server/

RUN mvn clean package

FROM adoptopenjdk/openjdk11:alpine-jre

RUN addgroup -S spring && adduser -S spring -G spring

RUN mkdir -p /files && \
chown -R spring:spring /files

USER spring:spring


VOLUME /files

WORKDIR /app

COPY --from=build /usr/src/config-server/target/config-server-0.0.1-SNAPSHOT.jar /app/app.jar

EXPOSE 8888

ENTRYPOINT ["java", "-jar", "app.jar"]
但它一直给我这个输出错误:
Building config-server
Step 1/13 : FROM maven:3.6.3-adoptopenjdk-11 as build
---> 739e519745cd
Step 2/13 : WORKDIR /usr/src/config-server/
---> Using cache
---> da21e56bb1f0
Step 3/13 : COPY . /usr/src/config-server/
---> Using cache
---> 08a5585f625f
Step 4/13 : RUN mvn clean package
---> Running in ed76a0ae6b41
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.erickmob.petclinic:config-server:1.0.0-SNAPSHOT: Could not find artifact com.erickmob.pet-clinic:pet-clinic:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.erickmob.petclinic:config-server:1.0.0-SNAPSHOT (/usr/src/config-server/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for com.erickmob.petclinic:config-server:1.0.0-SNAPSHOT: Could not find artifact com.erickmob.pet-clinic:pet-clinic:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
ERROR: Service 'config-server' failed to build: The command '/bin/sh -c mvn clean package' returned a non-zero code: 1
如果我制作 mvn clean安装在根文件夹或 config-server 文件夹上,一切正常,但是当我尝试运行 docker-compose build 时,它给我一个错误,说找不到父 pom。

最佳答案

这是不是 Docker,但 Maven。
您正在构建您的 config-server/仅项目(这里是 Docker 在中间时),但发送给 Docker 的“上下文”是 只是里面有什么config-server/而不是整个项目。 build config-server/您需要整个项目,因为您正在引用/使用父 POM。

关于spring-boot - 无法对 spring 微服务多模块应用程序进行 dockerize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63102497/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com