docker-maven-plugin Dockerfile 方式简单应用

司空玮
2023-12-01

插件坐标

groupId :com.spotify
artifactId : docker-maven-plugin
version : 1.2.2

maven 使用方式

    <build>
        <finalName>${artifactId}</finalName>
        <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.2.2</version>
                <configuration>
                    <imageName>order-api</imageName>
					<!-- 
                        指定 Dockerfile 所在的文件目录
                     -->
                    <dockerDirectory>${project.basedir}</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
        </plugins>
    </build>

Dockerfile

FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/xxx.jar
COPY ${JAR_FILE} xxx.jar
ENTRYPOINT ["java","-jar","/xxx.jar"]

build image

mvn clean package docker:build -Dmaven.test.skip=true -X

参考

https://spring.io/guides/gs/spring-boot-docker/#:~:text=This%20Dockerfile%20is%20very%20simple%2C%20but%20it%20is,as%20app.jar%2C%20which%20is%20run%20in%20the%20ENTRYPOINT.

https://blog.csdn.net/weixin_44424668/article/details/104062822

 类似资料: