docker 部署spring boot

1.在pom中添加docker-依赖

<plugin>
 <groupId>com.spotify</groupId>
 <artifactId>docker-maven-plugin</artifactId>
 <version>0.4.14</version>
 <configuration>
   <imageName>${project.groupId}.${project.artifactId}</imageName>
   <dockerDirectory>${project.build.outputDirectory}</dockerDirectory>
   <dockerHost>http://127.0.0.1:2375</dockerHost>
   <resources>
     <resource>
       <directory>${project.build.directory}</directory>
       <include>${project.build.finalName}.jar</include>
     </resource>
   </resources>
 </configuration> 
</plugin>

在resources下添加Dockerfile文件:
jar包内容:

FROM java:8
ADD docklean-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
CMD java -jar app.jar

war包内容:

FROM tomcat:8
MAINTAINER "hoaven"<hoaven@163.com>
ADD docklean-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/app.war
EXPOSE 8081
CMD ["catalina.sh", "run"]

打包:

mvn clean 
mvn package

上传镜像:

mvn clean install docker:build

cmd查看镜像:

docker images

运行项目:

docker run -p 8081:8080 -t wxz.docklean:latest

测试:
docker 部署spring boot_第1张图片

移除镜像:

docker mr 镜像id

推送到kubeenete:

你可能感兴趣的:(docker 部署spring boot)