欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

maven插件 dockefile完整代码配置流程实例

程序员文章站 2024-03-21 18:20:04
...

dockerfile 插件 (上面的是docker插件,推荐用这个)

前提准备:maven的机器上已经配置好了DOCKER_HOST, 不管是windows还是linux

maven插件 dockefile完整代码配置流程实例
maven插件 dockefile完整代码配置流程实例

FROM java:8
ARG JAR_FILE
ADD target/${JAR_FILE} app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]

setting.xml

 <server>
      <id>registry.cn-hangzhou.aliyuncs.com</id>
      <username>a15037147487</username>
      <password>qwer123456</password>
      <configuration>
        <email>aaa@qq.com</email>
      </configuration>
    </server>

pom.xml

    <properties>
        <docker.image.prefix>registry.cn-hangzhou.aliyuncs.com</docker.image.prefix>
        <docker.image.midfix>wheatdr-cloud</docker.image.midfix>
        <java.version>1.8</java.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- 使用Maven插件直接将应用打包为一个Docker镜像 -->
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <version>1.3.6</version>
                <configuration>
                    <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
                    <repository>${docker.image.prefix}/${docker.image.midfix}/${project.artifactId}</repository>
                    <tag>${project.version}</tag>
                    <buildArgs>
                        <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
                    </buildArgs>
                    <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
                </configuration>
                <!-- 镜像构建完毕之后自动推送到仓库 -->
                <executions>
                    <execution>
                        <id>default</id>
                        <phase>install</phase>
                        <goals>
                            <goal>build</goal>
                            <goal>push</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

控制台执行的命令:

mvn install dockerfile:build dockerfile:push # 貌似install就包含后面的dockerfile
所以
mvn install  应该就可以

顺便请教大佬,maven插件 在 生命周期 如何看。比如这个。dockerfile插件怎么就加到install的生命周期了