多maven模块的Docker镜像(六角形架构)
我正在尝试使用带有多个 Maven 模块的 dockerfile 创建一个 docker 映像,但遇到了很多错误。 这是我的架构
+ -- MyMainProject
+ -- application <- Module 1
| ` -- pom.xml
+ -- domain <- Module 2
| ` -- pom.xml
+ -- bootloader <- Module 3
| `src/main/java/BootloaderApplicationLuncher (Java application launcher)
| ` -- pom.xml
+ -- infrastructure <- Module 4 (has 3 modules)
+ -- infrastructure 1 <- Module 4.1
| ` -- pom.xml
+ -- infrastructure 2 <- Module 4.2
| ` -- pom.xml
+ -- infrastructure 3 <- Module 4.3
| ` -- pom.xml
| -- pom.xml
这是我的 dockerfile:
FROM maven:3.6-alpine as build
WORKDIR /home/app
COPY application/pom.xml application/pom.xml
COPY domain/pom.xml domain/pom.xml
COPY bootloader/pom.xml bootloader/pom.xml
COPY infrastructure/pom.xml infrastructure/pom.xml
COPY infrastructure/adapter-persistence-spring-data-jpa/pom.xml infrastructure/adapter-persistence-spring-data-jpa/pom.xml
COPY infrastructure/adapter-persistence-spring-data-mongodb/pom.xml infrastructure/adapter-persistence-spring-data-mongodb/pom.xml
COPY infrastructure/adapter-rest/pom.xml infrastructure/adapter-rest/pom.xml
COPY pom.xml .
RUN mvn -B -e -C org.apache.maven.plugins:maven-dependency-plugin:3.1.2:go-offline
RUN mvn -f /home/app/pom.xml clean package
FROM maven:3.6-alpine as BUILDER
COPY --from=build /root/.m2 /root/.m2
COPY --from=build /home/app /home/app
COPY application/src /home/app/application/src
COPY domain/src /home/app/domain/src
COPY bootloader/src /home/app/bootloader/src
COPY infrastructure/src /home/app/infrastructure/src
COPY infrastructure/adapter-rest/src /home/app/infrastructure/adapter-rest/src
COPY infrastructure/adapter-persistence-spring-data-mongodb/src /home/app/infrastructure/adapter-persistence-spring-data-mongodb/src
COPY infrastructure/adapter-persistence-spring-data-jpa/src /home/app/infrastructure/adapter-persistence-spring-data-jpa/src
#RUN mvn -B -e clean install -DskipTests=true
FROM openjdk:8-alpine
EXPOSE 8080
WORKDIR /home/app
COPY --from=builder /home/app/bootloader/target/bootloader-1.0-SNAPSHOT.jar .
ENTRYPOINT ["java", "-jar", "/home/app/bootloader/bootloader-1.0-SNAPSHOT.jar"]
错误: 无法在项目应用程序上执行目标:无法解析项目 io.example:application:jar:1.0-SNAPSHOT 的依赖项:无法在 spring-releases 中找到工件 io.example:domain:jar:1.0-SNAPSHOT (< a href="https://repo.spring.io/libs-release" rel="nofollow noreferrer">https://repo.spring.io/libs-release) ->; [帮助1]
I am trying to create a docker image with a dockerfile with multiple maven modules and I faced alot of erros.
Here is my architecture
+ -- MyMainProject
+ -- application <- Module 1
| ` -- pom.xml
+ -- domain <- Module 2
| ` -- pom.xml
+ -- bootloader <- Module 3
| `src/main/java/BootloaderApplicationLuncher (Java application launcher)
| ` -- pom.xml
+ -- infrastructure <- Module 4 (has 3 modules)
+ -- infrastructure 1 <- Module 4.1
| ` -- pom.xml
+ -- infrastructure 2 <- Module 4.2
| ` -- pom.xml
+ -- infrastructure 3 <- Module 4.3
| ` -- pom.xml
| -- pom.xml
Here is my dockerfile:
FROM maven:3.6-alpine as build
WORKDIR /home/app
COPY application/pom.xml application/pom.xml
COPY domain/pom.xml domain/pom.xml
COPY bootloader/pom.xml bootloader/pom.xml
COPY infrastructure/pom.xml infrastructure/pom.xml
COPY infrastructure/adapter-persistence-spring-data-jpa/pom.xml infrastructure/adapter-persistence-spring-data-jpa/pom.xml
COPY infrastructure/adapter-persistence-spring-data-mongodb/pom.xml infrastructure/adapter-persistence-spring-data-mongodb/pom.xml
COPY infrastructure/adapter-rest/pom.xml infrastructure/adapter-rest/pom.xml
COPY pom.xml .
RUN mvn -B -e -C org.apache.maven.plugins:maven-dependency-plugin:3.1.2:go-offline
RUN mvn -f /home/app/pom.xml clean package
FROM maven:3.6-alpine as BUILDER
COPY --from=build /root/.m2 /root/.m2
COPY --from=build /home/app /home/app
COPY application/src /home/app/application/src
COPY domain/src /home/app/domain/src
COPY bootloader/src /home/app/bootloader/src
COPY infrastructure/src /home/app/infrastructure/src
COPY infrastructure/adapter-rest/src /home/app/infrastructure/adapter-rest/src
COPY infrastructure/adapter-persistence-spring-data-mongodb/src /home/app/infrastructure/adapter-persistence-spring-data-mongodb/src
COPY infrastructure/adapter-persistence-spring-data-jpa/src /home/app/infrastructure/adapter-persistence-spring-data-jpa/src
#RUN mvn -B -e clean install -DskipTests=true
FROM openjdk:8-alpine
EXPOSE 8080
WORKDIR /home/app
COPY --from=builder /home/app/bootloader/target/bootloader-1.0-SNAPSHOT.jar .
ENTRYPOINT ["java", "-jar", "/home/app/bootloader/bootloader-1.0-SNAPSHOT.jar"]
Error:
Failed to execute goal on project application: Could not resolve dependencies for project io.example:application:jar:1.0-SNAPSHOT: Could not find artifact io.example:domain:jar:1.0-SNAPSHOT in spring-releases (https://repo.spring.io/libs-release) -> [Help 1]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论