<!--maven docker 打包插件--> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.13</version> <executions> <execution> <id>build-image</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> <configuration> <!--覆蓋相同標籤的鏡像--> <registryUrl>192.168.1.150:5000</registryUrl> <pushImage>true</pushImage> <forceTags>false</forceTags> <dockerHost>http://192.168.1.150:2375</dockerHost> <imageName>192.168.1.150:5000/insight/${project.build.finalName}:${application.version}</imageName> <dockerDirectory>${project.basedir}/dockerfile</dockerDirectory> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> <buildArgs> <JAR_FILE>${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> </plugin>
項目根目錄建立一個 dockerfile 目錄,並新建 Dockerfile 文件java
FROM java:8 VOLUME /tmp ARG JAR_FILE ADD ${JAR_FILE} app.jar RUN bash -c 'touch /app.jar' EXPOSE 8002 ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"]
mvn clean install -Dmaven.test.skip=true -Pdevelop
,這樣就能夠把 jar 包打成鏡像,並上傳到私有倉庫中了。docker