1.添加docker编译插件
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
2.在项目根目录下添加Dockerfile
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD ./target/demo-0.0.1-SNAPSHOT.jar demo.jar
RUN sh -c 'touch /demo.jar'
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /demo.jar"]
3.使用如下命令创建镜像
mvn clean package dockerfile:build
4.docker images查看镜像
5.然后运行该镜像
docker run -p 8080:8080 -t 8d630a1cbc14
6.然后浏览器访问写的测试接口