Docker怎么部署springboot项目-创新互联
这篇文章主要讲解了“Docker怎么部署springboot项目”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Docker怎么部署springboot项目”吧!
创新互联建站网络公司拥有10多年的成都网站开发建设经验,近千家客户的共同信赖。提供成都网站建设、成都做网站、网站开发、网站定制、买友情链接、建网站、网站搭建、响应式网站开发、网页设计师打造企业风格,提供周到的售前咨询和贴心的售后服务创建项目
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项目这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联网站建设公司,,小编将为大家推送更多相关知识点的文章,欢迎关注!
网站名称:Docker怎么部署springboot项目-创新互联
文章来源:http://azwzsj.com/article/djocpc.html