将SpringBoot项目发布到Docker

Published on in Java是世界上最好的语言 with 0 views and 0 comments

1.将SpringBoot项目打jar包

pom.xml增加spring-boot-maven-plugin插件
使用右侧maven-Lifecycle-package打jar包
使用java -jar *-1.0.0.jar测试可用

2.新建Dockerfile

FROM java:8
VOLUME /tmp
ADD love-0.0.1-SNAPSHOT.jar /love.jar
ENTRYPOINT["java","-Djava.security.egd=file:/dev/./urandom","-jar","/love.jar"]

3.将jar包拷贝到和Dockerfile同文件夹

4.创建镜像

docker build -f /usr/local/lovecaining/Dockerfile -t lovecaining

5.运行镜像

docker run -d -p 8088:8088 --name lovecaining lovecaining