使用IDEA的Docker插件一键部署SpringBoot项目

使用IDEA的Docker插件一键部署SpringBoot项目,是打包运维变得非常便利,linux上安装docker->IDEA安装插件连接到Docker服务->项目打包->docker打包->linux运行docker服务。

配置文件:



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.4.2
         
    
    com.docker.my.test
    dtest
    0.0.1-SNAPSHOT
    dtest
    Demo project for Spring Boot
    
        1.8
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
        ${project.artifactId}

        
            
                org.springframework.boot
                spring-boot-maven-plugin
            


            
            
                com.spotify
                docker-maven-plugin
                1.0.0
                
                
                    
                        build-image
                        
                        package
                        
                            build
                        
                    
                

                
                    
                    ww/${project.artifactId}

                    
                    
                        latest
                    

                    
                    java
                    
                    
                    /ROOT

                    
                    ["java", "-version"]

                    
                    ["java", "-jar", "/${project.build.finalName}.jar"]

                    
                    http://xxxxxx:2375

                    
                    
                        
                            /
                            
                            ${project.build.directory}
                            
                            ${project.build.finalName}.jar
                        
                    
                
            
        
    


Docker插件配置:

使用IDEA的Docker插件一键部署SpringBoot项目_第1张图片

先打包项目

使用IDEA的Docker插件一键部署SpringBoot项目_第2张图片

target下面出现

使用IDEA的Docker插件一键部署SpringBoot项目_第3张图片

双击docker-build

使用IDEA的Docker插件一键部署SpringBoot项目_第4张图片

镜像完成

使用IDEA的Docker插件一键部署SpringBoot项目_第5张图片

Docker运行,注意-p为端口映射:

[root@localhost ~]# docker run --name web -d -p 8080:8080   ww/dtest:latest
65bb7f9434c0b09fbada4885ab15268b411cbcfcdd2c40077bb52938a7756d9d

返回的这个字符串就是这个进程ID,查看日志需要

Docker日志查看:

[root@localhost ~]# docker logs 65bb7f9434

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

2021-02-04 06:10:30.420  INFO 1 --- [           main] c.docker.my.test.dtest.DtestApplication  : Starting DtestApplication v0.0.1-SNAPSHOT using Java 1.8.0_111 on 65bb7f9434c0 with PID 1 (/dtest.jar started by root in /ROOT)
2021-02-04 06:10:30.462  INFO 1 --- [           main] c.docker.my.test.dtest.DtestApplication  : No active profile set, falling back to default profiles: default
2021-02-04 06:10:34.517  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-02-04 06:10:34.702  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-02-04 06:10:34.703  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-02-04 06:10:35.168  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-02-04 06:10:35.168  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4483 ms
2021-02-04 06:10:36.691  INFO 1 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-02-04 06:10:37.398  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-02-04 06:10:37.456  INFO 1 --- [           main] c.docker.my.test.dtest.DtestApplication  : Started DtestApplication in 8.711 seconds (JVM running for 10.272)
2021-02-04 06:10:37.877  INFO 1 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-02-04 06:10:37.877  INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2021-02-04 06:10:37.878  INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
call .............
call .............
call .............
call .............


浏览器查看,注意是服务器地址:

使用IDEA的Docker插件一键部署SpringBoot项目_第6张图片

 

 

 

你可能感兴趣的:(SpringBoot,docker,linux,java,springboot)