Docker如何部署springboot项目
这篇文章主要为大家展示了“Docker如何部署springboot项目”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Docker如何部署springboot项目”这篇文章吧。
尖扎ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!
创建项目
pom.xml
4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.9.RELEASE com.topcheer docker 0.0.1-SNAPSHOT docker Demo project for Spring Boot 1.8 topcheer org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin com.spotify docker-maven-plugin 1.0.0 ${docker.image.prefix}/${project.artifactId} src/main/docker / ${project.build.directory} ${project.build.finalName}.jar
启动类
@SpringBootApplication @Controller public class DockerApplication { public static void main(String[] args) { SpringApplication.run(DockerApplication.class, args); } @RequestMapping("/user/find") @ResponseBody public Object findUser(){ Mapmap = new HashMap<>(); map.put("name", "xdclass.net"); map.put("age","28"); return map; } }
由于harbor没有安装,无法把镜像推到私有镜像仓库上,所以先手动执行。
mvn install,然后把dockerfile和jar包放到一起
[root@topcheer docker]# ll 总用量 16452 -rw-r--r-- 1 root root 168 10月 28 14:24 Dockerfile -rw-r--r-- 1 root root 16842487 10月 28 14:17 docker.jar [root@topcheer docker]# cat Dockerfile FROM java:8 VOLUME /tmp ADD docker.jar app.jar RUN bash -c 'touch /app.jar' EXPOSE 8080 ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] [root@topcheer docker]#
编译成镜像并启动
[root@topcheer docker]# docker build -f Dockerfile -t boot . Sending build context to Docker daemon 16.85 MB Step 1/6 : FROM java:8 ---> d23bdf5b1b1b Step 2/6 : VOLUME /tmp ---> Running in 35037b5a7791 ---> e96b96457c78 Removing intermediate container 35037b5a7791 Step 3/6 : ADD docker.jar app.jar ---> 06bcfdcff437 Removing intermediate container 2e2e5e559ae4 Step 4/6 : RUN bash -c 'touch /app.jar' ---> Running in 16441febc271 ---> 1779caa23f77 Removing intermediate container 16441febc271 Step 5/6 : EXPOSE 8080 ---> Running in 14dd752ce247 ---> 505044f5cdf8 Removing intermediate container 14dd752ce247 Step 6/6 : ENTRYPOINT java -Djava.security.egd=file:/dev/./urandom -jar /app.jar ---> Running in 832e4ca95dd2 ---> 1cb7bd139478 Removing intermediate container 832e4ca95dd2 Successfully built 1cb7bd139478 [root@topcheer docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE boot latest 1cb7bd139478 About a minute ago 677 MB registry.cn-hangzhou.aliyuncs.com/dalianpai/topcheer zipkin 17c2bb09f482 6 days ago 154 MB docker.io/MySQL latest c8ee894bd2bd 11 days ago 456 MB elasticsearch latest 874179f19603 4 weeks ago 771 MB docker.io/nacos/nacos-server latest a4229ac5cc19 4 weeks ago 710 MB springbootdemo4docker latest cd13bc7f56a0 5 weeks ago 678 MB docker.io/tomcat latest ee48881b3e82 6 weeks ago 506 MB docker.io/rabbitmq latest a00bc560660a 6 weeks ago 147 MB docker.io/centos latest 67fa590cfc1c 2 months ago 202 MB docker.io/redis latest f7302e4ab3a8 2 months ago 98.2 MB docker.io/rabbitmq 3.7.16-management 3f92e6354d11 3 months ago 177 MB docker.io/elasticsearch 6.8.0 d0b291d7093b 5 months ago 895 MB docker.io/hello-world latest fce289e99eb9 10 months ago 1.84 kB docker.io/java 8 d23bdf5b1b1b 2 years ago 643 MB [root@topcheer docker]# docker run -d -p 8080:8080 boot 882ff5209aa2f40972a914b901750a50320faea65100b33e57b9c8a41533ca0b
测试
以上是“Docker如何部署springboot项目”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!
网站栏目:Docker如何部署springboot项目
文章链接:http://azwzsj.com/article/jiipjc.html