最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用Docker部署Spring Boot項(xiàng)目的實(shí)現(xiàn)步驟

 更新時(shí)間:2021年12月29日 09:20:14   作者:初念初戀  
本文主要介紹了使用Docker部署Spring Boot項(xiàng)目的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

創(chuàng)建一個(gè)簡(jiǎn)單的springboot項(xiàng)目

一、在 pom.xml 中 ,使用 Spring Boot 2.2.10 相關(guān)依賴

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.10.RELEASE</version>
</parent>

二、添加 web 和測(cè)試依賴

<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>

三、創(chuàng)建一個(gè) DockerController,在其中有一個(gè)hello()方法,訪問(wèn)時(shí)返回:hello,nihao

@RestController
public class DockerController {
 
    @RequestMapping("/hello")
    public String hello() {
        return "hello,nihao";
    }
}

四、啟動(dòng)類

@SpringBootApplication
public class DockerApplication {

 public static void main(String[] args) {
  SpringApplication.run(DockerApplication.class, args);
 }
}

添加完畢后啟動(dòng)項(xiàng)目,啟動(dòng)成功后瀏覽器訪問(wèn):http://localhost:8080/hello,頁(yè)面返回:hello,nihao,說(shuō)明 Spring Boot 項(xiàng)目配置正常。

使用 Docker 部署 Spring Boot 項(xiàng)目

一、將項(xiàng)目打成jar包,拷貝到服務(wù)器上,測(cè)試一下

[root@jiangwang springbootDemo]# ls
demo-0.0.1-SNAPSHOT.jar  Dockerfile
[root@jiangwang springbootDemo]# java -jar demo-0.0.1-SNAPSHOT.jar 

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.2.10.RELEASE)

2021-03-18 14:49:18.241  INFO 12886 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication v0.0.1-SNAPSHOT on jiangwang with PID 12886 (/home/springbootDemo/demo-0.0.1-SNAPSHOT.jar started by root in /home/springbootDemo)
2021-03-18 14:49:18.244  INFO 12886 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2021-03-18 14:49:19.924  INFO 12886 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-03-18 14:49:19.938  INFO 12886 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-03-18 14:49:19.938  INFO 12886 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.38]
2021-03-18 14:49:20.013  INFO 12886 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-03-18 14:49:20.014  INFO 12886 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1657 ms
2021-03-18 14:49:20.321  INFO 12886 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-18 14:49:20.520  INFO 12886 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-03-18 14:49:20.523  INFO 12886 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 2.899 seconds (JVM running for 3.369)

二、看到 Spring Boot 的啟動(dòng)日志后表明環(huán)境配置沒(méi)有問(wèn)題,編輯Dockerfile文件:

FROM java:8
COPY *.jar /app.jar

CMD ["--server.port=8080"]

EXPOSE 8080

ENTRYPOINT ["java","-jar","/app.jar"]

三、接下來(lái)我們使用 Dockerfile 構(gòu)建鏡像:

## 構(gòu)建鏡像
[root@jiangwang springbootDemo]# docker build -t springboot-demo .
Sending build context to Docker daemon  17.72MB
Step 1/5 : FROM java:8
 ---> d23bdf5b1b1b
Step 2/5 : COPY *.jar /app.jar
 ---> f4d6aeabd3f0
Step 3/5 : CMD ["--server.port=8080"]
 ---> Running in a6311f7cf7b5
Removing intermediate container a6311f7cf7b5
 ---> d8117b10cefa
Step 4/5 : EXPOSE 8080
 ---> Running in ae180be637bb
Removing intermediate container ae180be637bb
 ---> f16702c75ab6
Step 5/5 : ENTRYPOINT ["java","-jar","/app.jar"]
 ---> Running in fafa00625666
Removing intermediate container fafa00625666
 ---> d4c3e225699d
Successfully built d4c3e225699d
Successfully tagged springboot-demo:latest

四、運(yùn)行鏡像:

# 運(yùn)行鏡像
[root@jiangwang springbootDemo]# docker run -d -p 39005:8080 --name my-springboot springboot-demo
7ac35852cb91cb10612cd28fdbe7c50c7c59df4cccf19b2f1d30dcabbfe501f4
[root@jiangwang springbootDemo]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS          PORTS                     NAMES
7ac35852cb91   springboot-demo       "java -jar /app.jar …"   33 seconds ago   Up 32 seconds   0.0.0.0:39005->8080/tcp   my-springboot
[root@jiangwang springbootDemo]# curl localhost:39005/hello
hello,nihao[root@jiangwang springbootDemo]# 

五、瀏覽器輸入外網(wǎng)網(wǎng)址訪問(wèn)一下:

這里你的外網(wǎng)39005端口首先要開(kāi)放了,可以去安全組設(shè)置

說(shuō)明使用 Docker 部署 Spring Boot 項(xiàng)目成功!

到此這篇關(guān)于使用Docker部署Spring Boot項(xiàng)目的實(shí)現(xiàn)步驟的文章就介紹到這了,更多相關(guān)Docker部署Spring Boot內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

监利县| 五华县| 米泉市| 扶绥县| 丹东市| 自治县| 社会| 昌黎县| 长沙县| 通化市| 榆林市| 大方县| 玉林市| 方城县| 南阳市| 珠海市| 墨竹工卡县| 措美县| 平遥县| 磴口县| 游戏| 舒城县| 怀化市| 桐城市| 兰溪市| 大同县| 游戏| 宁强县| 张家港市| 临湘市| 资兴市| 安仁县| 略阳县| 鄂托克前旗| 浦城县| 临清市| 安图县| 大英县| 克东县| 景泰县| 桐庐县|