docker-maven-plugin的pom配置

史修谨
2023-12-01
<build>
    <plugins>
        <!--maven docker插件-->
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>${docker.maven.plugin.version}</version>
            <!--将插件绑定在某个phase执行-->
            <executions>
                <execution>
                    <id>buid-image</id>
                    <!--用户只需执行mvn package,自动执行mvn docker:build-->
                    <phase>package</phase>
                    <goals>
                        <goal>build</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!--指定镜像名-->
                <imageName>xx/${project.artifactId}:${project.version}</imageName>

                <!--指定标签-->
                <imageTags>
                    <imageTag>latest</imageTag>
                </imageTags>

                <!--指定基础镜像-->
                <baseImage>java:8</baseImage>

                <!--指定远程docker地址-->
                <!--TLS证书,使用https协议-->
                <dockerHost>https://47.123.123.123:2376</dockerHost>
                <!--配置TLS证书在系统中的路径-->
                <dockerCertPath>/Users/root/docker-ca</dockerCertPath>
                <entryPoint>
                    ["java", "-jar", "-Dspring.profiles.active=prod","/${project.build.finalName}.jar"]
                </entryPoint>

                <!--复制jar包到docker容器指定目录-->
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <!--jar包在项目中生成的路径,即对应的target目录-->
                        <directory>${project.build.directory}</directory>
                        <!--指定需要复制的文件-->
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
            </configuration>
        </plugin>
    </plugins>
</build>
<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <configuration>
        <dockerHost>${docker.host}</dockerHost>
        <imageName>${docker.image.prefix}/${project.name}:${project.version}</imageName>
        <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
        <forceTags>true</forceTags>
        <pushImageTag>true</pushImageTag>
        <serverId>${docker.server.id}</serverId>
        <imageTags>
        <imageTag>${project.version}</imageTag>
        </imageTags>
        <buildArgs>
        <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
        </buildArgs>
        <resources>
        <resource>
        <targetPath>/</targetPath>
        <directory>${project.build.directory}</directory>
        <include>${project.build.finalName}.jar</include>
        </resource>
        </resources>
    </configuration>
</plugin>
 类似资料: