不多说,上代码

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>1.3.4</version>
                <executions>
                    <execution>
                        <id>docker-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/docker/</directory>
                                    <filtering>false</filtering>
                                    <excludes>
                                        <exclude>**/*.yml</exclude>
                                    </excludes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <version>1.3.4</version>
                <configuration>
                    <repository>guard</repository>
                    <tag>${project.version}</tag>
                    <contextDirectory>${project.build.directory}</contextDirectory>
                </configuration>
            </plugin>

目录结构:

src
----main
--------docker
----------------Dockerfile
--------java

运行命令:

mvn clean package dockerfile:build

在运行程序时,会将docker/dockerfile 文件,copy 到target 文件下