[英]Can't dockerize spring micro-services multi module app
我正在使用 JAVA 11、maven、spring 構建應用程序。 它有一個根 pom 來組織所有子模塊,如下所示: https://github.com/erickmob/spring-petclinic-microservices
這是項目結構:
我試圖在根項目上創建這個 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
在配置服務器中這個 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"]
但它一直給我這個 output 錯誤:
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
如果我在根文件夾或 config-server 文件夾上進行mvn clean
install,一切正常,但是當我嘗試運行 docker-compose build 時,它給了我一個錯誤,說找不到父 pom。
這不是真正的 Docker,而是 Maven。
您正在構建您的config-server/
項目(此時 Docker位於中間),但發送到 Docker 的“上下文”只是config-server/
內部的內容,而不是整個項目。 要構建config-server/
您需要整個項目,因為您正在引用/使用父POM。
國際大學聯合會,
docker-compose.yml
version: "2"
services:
config-server:
build:
context: ./
dockerfile: Dockerfile
image: config-server
container_name: config-server
mem_limit: 512M
ports:
- 8888:8888
Dockerfile
FROM maven:3.6.3-adoptopenjdk-11 as build
COPY . /usr/src/
WORKDIR /usr/src/
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"]
運行以下命令docker-compose up -d
日志:
root@ubuntu:/home/sathya/Desktop/stackoverflo/docker/spring-boot/spring-petclinic-microservices# docker-compose up -d
Building config-server
Step 1/13 : FROM maven:3.6.3-adoptopenjdk-11 as build
---> a4579cf3debf
Step 2/13 : COPY . /usr/src/
---> 9841e6033a86
Step 3/13 : WORKDIR /usr/src/
---> Running in aa2526d60d42
Removing intermediate container aa2526d60d42
---> 6e3b35f66218
Step 4/13 : RUN mvn clean package
---> Running in 5b2bac4dcef4
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.3.2.RELEASE/spring-boot-starter-parent-2.3.2.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.3.2.RELEASE/spring-boot-starter-parent-2.3.2.RELEASE.pom (8.6 kB at 2.2 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-dependencies/2.3.2.RELEASE/spring-boot-dependencies-2.3.2.RELEASE.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-dependencies/2.3.2.RELEASE/spring-boot-dependencies-2.3.2.RELEASE.pom (122 kB at 25 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/datastax/oss/java-driver-bom/4.6.1/java-driver-bom-4.6.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/com/datastax/oss/java-driver-bom/4.6.1/java-driver-bom-4.6.1.pom (3.8 kB at 3.1 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/io/dropwizard/metrics/metrics-bom/4.1.11/metrics-bom-4.1.11.pom
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.