首页 > 解决方案 > docker-maven-plugin 没有创建 dockerfile

问题描述

我正在使用 docker-maven-plugin 为 Java 微服务创建 dockerfile 和 docker 映像。当我运行命令mvn package -DskipTest=true时,它不会创建 Dockerfile。

我正在使用 docker-maven-plugin 为 Java 微服务创建 dockerfile 和 docker 映像。当我运行命令时mvn package -DskipTest=true。它成功运行,没有任何错误,但它不会生成 Dockerfile。查看发送到屏幕的消息,尽管该插件在“构建”中配置,但它看起来并没有运行

以下是 pom.xml 中构建任务的配置:

 <build>
                <plugins>
                        <plugin>
                                <groupId>org.springframework.boot</groupId>
                                <artifactId>spring-boot-maven-plugin</artifactId>
                        </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.1.1</version>
                <configuration>
                    <imageName>explorecali-${ec-profile}</imageName>
                    <baseImage>java</baseImage>
                    <entryPoint>["java", "-Dspring.profiles.active=${ec-profile}", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                    <forceTags>true</forceTags>
                    <buildArgs>
                        <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
                    </buildArgs>
                </configuration>
            </plugin>

        </plugins>
        </build>

没有错误消息,但没有 Dockefile。以下是我运行它时向屏幕发出的消息:

[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< com.example.ec:explorecali >---------------------
[INFO] Building explorecali 2.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ explorecali ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] Copying 7 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ explorecali ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ explorecali ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\fikhas\dev\spring\Ex_Files_Ext_Docker_Spring_Boot\Exercise Files\Ch05\05_05\explorecali\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ explorecali ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ explorecali ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ explorecali ---
[INFO] Building jar: C:\Users\fikhas\dev\spring\Ex_Files_Ext_Docker_Spring_Boot\Exercise Files\Ch05\05_05\explorecali\target\explorecali-2.0.0-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.1.RELEASE:repackage (default) @ explorecali ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.576 s
[INFO] Finished at: 2019-08-07T13:25:58-04:00
[INFO] ------------------------------------------------------------------------

标签: mavendockerdockerfile

解决方案


您可能需要运行“maven package docker:build”而不仅仅是“maven package”。为了将 docker build 绑定到 maven 阶段,您还可以尝试以下操作:

<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>

来自https://github.com/spotify/docker-maven-plugin#bind-docker-commands-to-maven-phases


推荐阅读