项目引入maven-docker插件
<properties> <docker.image.prefix>baldr</docker.image.prefix> </properties> <build> <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <configuration> <imageName>${docker.image.prefix}/${project.artifactId}</imageName> <dockerHost>http://192.168.0.102:21800</dockerHost> <dockerDirectory>src/main/docker</dockerDirectory> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> <dependencies> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>1.1.1</version> </dependency> </dependencies> </plugin> </plugins> </build>
dockerfile示例
FROM openjdk:11-jre-slim MAINTAINER songyan EXPOSE 8081 ENV TZ=Asia/Shanghai RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN mkdir -p /usr/local/jar COPY baldr-test-server-0.0.1-SNAPSHOT.jar /usr/local/jar/baldr-test-server-0.0.1-SNAPSHOT.jar ENTRYPOINT ["java","-jar","/usr/local/jar/baldr-test-server-0.0.1-SNAPSHOT.jar"]
idea安装docker插件
安装完需要重启idea才能生效
idea配置docker插件
点击docker build ,成功之后,该项目对应的镜像就在docker images列表中了