Docker部署springboot項(xiàng)目實(shí)例解析
這篇文章主要介紹了docker部署springboot項(xiàng)目實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
創(chuàng)建項(xiàng)目
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.topcheer</groupId> <artifactId>docker</artifactId> <version>0.0.1-SNAPSHOT</version> <name>docker</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <docker.image.prefix>topcheer</docker.image.prefix> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.0.0</version> <configuration> <imageName>${docker.image.prefix}/${project.artifactId}</imageName> <dockerDirectory>src/main/docker</dockerDirectory> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> </plugins> </build> </project>
啟動(dòng)類(lèi)
@SpringBootApplication @Controller public class DockerApplication { public static void main(String[] args) { SpringApplication.run(DockerApplication.class, args); } @RequestMapping("/user/find") @ResponseBody public Object findUser(){ Map<String, String > map = new HashMap<>(); map.put("name", "xdclass.net"); map.put("age","28"); return map; } }
由于harbor沒(méi)有安裝,無(wú)法把鏡像推到私有鏡像倉(cāng)庫(kù)上,所以先手動(dòng)執(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]#
編譯成鏡像并啟動(dòng)
[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
測(cè)試
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 利用Dockerfile部署SpringBoot項(xiàng)目的方法
- 使用Docker部署SpringBoot項(xiàng)目的實(shí)現(xiàn)方法
- 詳解springboot項(xiàng)目docker部署實(shí)踐
- java通過(guò)Idea遠(yuǎn)程一鍵部署springboot到Docker詳解
- 在Idea中使用Docker部署SpringBoot項(xiàng)目的詳細(xì)步驟
- 基于idea把springboot項(xiàng)目部署到docker
- Linux+Docker+SpringBoot+IDEA一鍵自動(dòng)化部署的詳細(xì)步驟
- Springboot打包為Docker鏡像并部署的實(shí)現(xiàn)
- Springboot服務(wù)Docker化自動(dòng)部署的實(shí)現(xiàn)方法
- idea使用docker插件實(shí)現(xiàn)一鍵自動(dòng)化部署
相關(guān)文章
docker容器間跨宿主機(jī)通信-基于overlay的實(shí)現(xiàn)方法
這篇文章主要介紹了docker容器間跨宿主機(jī)通信-基于overlay的實(shí)現(xiàn)方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-02-02Docker快速部署主流腳本語(yǔ)言JavaScript的全過(guò)程
JavaScript是目前所有主流瀏覽器上唯一支持的腳本語(yǔ)言,這也是早期JavaScript的唯一用途,下面這篇文章主要給大家介紹了關(guān)于Docker快速部署主流腳本語(yǔ)言JavaScript的相關(guān)資料,需要的朋友可以參考下2023-02-02谷歌技術(shù)人員解決Docker鏡像體積太大問(wèn)題的方法
這篇文章主要介紹了谷歌技術(shù)人員解決Docker鏡像體積太大問(wèn)題的方法,涉及虛擬機(jī),谷歌docker鏡像構(gòu)建實(shí)踐及構(gòu)建工具bazel的介紹等相關(guān)內(nèi)容,具有一定參考價(jià)值,需要的朋友可以了解下。2017-11-11docker-compose啟動(dòng)redis集群的實(shí)現(xiàn)步驟
本文主要介紹了docker-compose啟動(dòng)redis集群的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07Docker Desktop啟動(dòng)失敗的解決(Docker failed to i
本文主要介紹了Docker Desktop啟動(dòng)失敗的解決(Docker failed to initialize Docker Desktop is shutting down),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03Docker容器在系統(tǒng)啟動(dòng)時(shí)自動(dòng)運(yùn)行配置方法
docker容器化可以使得環(huán)境相對(duì)獨(dú)立,減少污染,這篇文章主要給大家介紹了關(guān)于Docker容器在系統(tǒng)啟動(dòng)時(shí)自動(dòng)運(yùn)行配置的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-09-09如何自己搭建DockerHub實(shí)現(xiàn)過(guò)程解析
這篇文章主要介紹了如何自己搭建DockerHub實(shí)現(xiàn)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-10-10