DockerMaven使用

1.配置docker远程端口

vi /lib/systemd/system/docker.service
-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
#执行命令
systemctl daemon-reload
systemctl restart docker

1.配置pom.xml

<!-- docker 的 maven 插件,官网:
            https://github.com/spotify/docker-maven-plugin -->
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.4.13</version>
                <configuration>
                    <!-- 注意 imageName 一定要是符合正则 [a-z0-9-_.] 的,否则构建不会成功 -->
                    <!-- 详见: https://github.com/spotify/docker-maven-plugin
                    Invalid repository name ... only [a-z0-9-_.] are allowed-->
                    <imageName>eureka</imageName>
                    <baseImage>jdk1.8</baseImage>
                    <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                    <dockerHost>http://121.5.106.77:2375</dockerHost>
                </configuration>
            </plugin>

2.执行打包命令

mvn clean package docker:build
#执行过后,即可在远程查看构建得镜像