Fabric8 docker maven插件不能用于多模块项目上的compose.yml

我尝试使用Fabric8 docker-maven-plugin,但是我成功地为各个模块configuration插件并运行docker:build docker:start docker docker:build docker:start maven目标而不使用docker-compose.yml,但是我需要外部化端口并链接不同的模块,因此我打算使用docker-compose.yml。 以下是我的项目结构。

 --kp-parent | --- docker-compose.yml --- pom.xml | ---- rest1 | | | -- .maven-dockerignore | -- pom.xml | -- Dockerfile ---- rest2 | | | -- .maven-dockerignore | -- pom.xml | -- Dockerfile 

这是我的configuration

Dockerfile [除了不同的端口,rest1和rest2都使用相同的文件]

 FROM openjdk:8-jdk-alpine MAINTAINER 'Karthik Prasad' ARG IMAGE_VERSION ARG JAR_FILE ENV JAVA_OPTS="" LABEL version = IMAGE_VERSION VOLUME /tmp ADD /maven/${JAR_FILE}.jar app.jar ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] EXPOSE 8000 

.maven-dockerignore [在两个子模块相同的文件]

 target/** 

pom.xml [rest1和rest2的pom文件都是相同的,除了artifcatid和项目名称]

 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>rest2</artifactId> <packaging>jar</packaging> <name>rest2</name> <description>Demo project for Spring Boot</description> <parent> <groupId>com.kp.swasthik</groupId> <artifactId>kp-docker-multimodule-fabric8-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!-- https://mvnrepository.com/artifact/io.fabric8/docker-maven-plugin --> <plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> <configuration> <skip>false</skip> <images> <image> <external> <type>compose</type> <basedir>../</basedir> <ignoreBuild>true</ignoreBuild> </external> </image> </images> </configuration> </plugin> </plugins> </build> </project> 

父pom.xml

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.kp.swasthik</groupId> <artifactId>kp-docker-multimodule-fabric8-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>kp-docker-multimodule-fabric8-parent</name> <description>Microservice Parent Pom file</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.7.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <modules> <module>rest1</module> <module>rest2</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <docker.image.prefix>kp-ms</docker.image.prefix> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <pluginManagement> <plugins> <plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.22.1</version> <configuration> <skip>true</skip> <images> <image> <alias>${project.artifactId}</alias> <name>${docker.image.prefix}/${project.artifactId}:${project.version}</name> <build> <dockerFileDir>${project.basedir}</dockerFileDir> <assembly> <inline> <id>default</id> <fileSet> <directory>${project.build.directory}</directory> <outputDirectory>/</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> </inline> </assembly> </build> </image> </images> <buildArgs> <IMAGE_VERSION>${project.version}</IMAGE_VERSION> <JAR_FILE>${project.artifactId}-${project.version}</JAR_FILE> </buildArgs> </configuration> </plugin> </plugins> </pluginManagement> </build> </project> 

最后是docker-compose.yml

 version: '2' services: rest1: image: kp-ms/rest1:0.0.1-SNAPSHOT ports: - 8000:8000 rest2: image: kp-ms/rest2:0.0.1-SNAPSHOT ports: - 8001:8001 links: - rest1 

当我运行docker:build docker:start我得到以下错误。

 [ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.22.1:start (default-cli) on project rest1: I/O Error: Unable to pull 'kp-ms/rest2:0.0.1-SNAPSHOT' : repository kp-ms/rest2 not found: does not exist or no pull access (Not Found: 404) -> [Help 1] [ERROR] 

但是,如果我删除docker-compose.yml中的rest2节,生成进展良好,我能够find容器启动成功。

我注意到的另一个问题是,即使不在Docker-compose.yml中给图像名称生成失败,错误图像为空。 然而,我不知道为什么我需要提供图像不能插件映射插件configuration,因为我已经提供了别名。 正如你可以注意到我试图dynamic生成图像名称。

任何帮助解决这个问题,非常感谢。