5

docker-maven-plugin插件的使用

 2 years ago
source link: http://www.hechunbo.com/index.php/archives/414.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

docker-maven-plugin插件的使用

直接把jar包打成docker文件

官网地址如下

https://github.com/spotify/docker-maven-plugin

a,pom配置

<plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <!-- 需要配合 imageTags 使用, 对tag进行覆盖 -->
                    <forceTags>true</forceTags>
                    <imageTags>
<!--                        <imageTag>${project.version}</imageTag>-->
                        <imageTag>latest</imageTag>
                    </imageTags>
                    <imageName>${project.artifactId}</imageName>
<!--                    <newName>docker.io/hcb/mavendemo:${project.version}</newName>-->
                    <!-- docker远程服务器地址 -->
                    <dockerHost>http://192.168.133.141:2375</dockerHost>
                    <!-- Dockerfile文件存放目录 -->
                    <dockerDirectory>src/main/docker</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                               <!-- 把下面的几个文件*.jar 和lib文件夹, 和resources文件夹中的文件复制到docker目录下 -->
                            <include>${project.build.finalName}.jar</include>
                            <include>/lib/*</include>
                            <include>/resources/*</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>

执行完 mvn clean package docker:build以后, 可以看到会新生成一个images

也可以单独立执行mvn docker:build

clean是先清除,

package直接打包,

联合在一起就是先清除,再打包, 再打镜像.

重复执行会重复生成, 最好配置一下私有库.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK