這篇文章主要講解了“Docker怎么部署springboot項(xiàng)目”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Docker怎么部署springboot項(xiàng)目”吧!
創(chuàng)新互聯(lián)建站網(wǎng)絡(luò)公司擁有10多年的成都網(wǎng)站開發(fā)建設(shè)經(jīng)驗(yàn),近千家客戶的共同信賴。提供成都網(wǎng)站建設(shè)、成都做網(wǎng)站、網(wǎng)站開發(fā)、網(wǎng)站定制、買友情鏈接、建網(wǎng)站、網(wǎng)站搭建、響應(yīng)式網(wǎng)站開發(fā)、網(wǎng)頁設(shè)計(jì)師打造企業(yè)風(fēng)格,提供周到的售前咨詢和貼心的售后服務(wù)創(chuàng)建項(xiàng)目
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沒有安裝,無法把鏡像推到私有鏡像倉庫上,所以先手動執(zhí)行。
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項(xiàng)目”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對Docker怎么部署springboot項(xiàng)目這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!