插件地址:https://github.com/spotify/dockerfile-maven
依github上备注,只要在项目根上录上编写dockerfile,然后引用插件即可
- 编写Dockerfile
FROM anapsix/alpine-java ARG JAR_FILE ADD target/${JAR_FILE} app.jar EXPOSE 8080 ENTRYPOINT ["java","-jar","/app.jar"]
- 编写pom.xml
<plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>${dockerfile-maven-version}</version> <executions> <execution> <id>default</id> <goals> <goal>build</goal> <goal>push</goal> </goals> </execution> </executions> <configuration> <repository>spotify/foobar</repository> <tag>${project.version}</tag> <buildArgs> <JAR_FILE>${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> </plugin>
- 因为docker环境默认为localhost:2375的,故可设置环境变量DOCKER_HOST=tcp://ip:port