成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專(zhuān)欄INFORMATION COLUMN

使用docker Maven插件本地構(gòu)建docker鏡像并發(fā)布到遠(yuǎn)程服務(wù)器

Thanatos / 2621人閱讀

摘要:登錄網(wǎng)站,生成一個(gè)基本的應(yīng)用。將應(yīng)用導(dǎo)入并創(chuàng)建類(lèi)。連接,執(zhí)行命令,查看可用的鏡像執(zhí)行命令,使用鏡像啟動(dòng)容器。至此,使用插件構(gòu)建鏡像并運(yùn)行容器完成,訪問(wèn)路徑,獲得結(jié)果

1.登錄網(wǎng)站https://start.spring.io/,生成一個(gè)基本的SpringBoot應(yīng)用。

2.將應(yīng)用導(dǎo)入Eclipse IDE并創(chuàng)建Application類(lèi)。目錄結(jié)構(gòu)如下:

Application代碼如下:

package com.example.demo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@RestController
public class Application {
    
    @RequestMapping(value="/phone")
    public String index(){
        return "Hello World!";
    }
}

3.在pom.xml文件中增加插件配置:


            
                com.spotify
                docker-maven-plugin
                0.4.12
                
                    
                    
                    microservice-eureka-demo
                    java
                    ["java", "-jar", "/${project.build.finalName}.jar"]
                    
                        
                            /
                            ${project.build.directory}
                            ${project.build.finalName}.jar
                        
                    
                
            

4.pom.xml文件中增加依賴(lài):

          
            org.springframework.boot  
            spring-boot-starter-web  
        

5.配置本地環(huán)境變量,設(shè)置docker文件構(gòu)建主機(jī)(主機(jī)192.168.244.130已經(jīng)安裝完docker環(huán)境)

root@ubuntu-02:~# docker -v
Docker version 17.05.0-ce, build 89658be

本地環(huán)境變量配置如下:

6.進(jìn)入代碼目錄,執(zhí)行命令“mvn clean package docker:build”項(xiàng)目編譯成功。

[INFO]
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ dockerdemo ---
[INFO] Building jar: C:UsersSeanDownloadsdemodemo	argetdockerdemo-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.4.RELEASE:repackage (default) @ dockerdemo ---
[INFO]
[INFO] --- docker-maven-plugin:0.4.12:build (default-cli) @ dockerdemo ---
[INFO] Copying C:UsersSeanDownloadsdemodemo	argetdockerdemo-0.0.1-SNAPSHOT.jar -> C:UsersSeanDownloadsdemodemo	argetdockerdockerdemo-0.0.1-SNAPSHOT.jar
[INFO] Building image microservice-eureka-demo
Step 1/3 : FROM java
 ---> d23bdf5b1b1b
Step 2/3 : ADD /dockerdemo-0.0.1-SNAPSHOT.jar //
 ---> e1b3c3de711c
Removing intermediate container a9e57b1d9883
Step 3/3 : ENTRYPOINT java -jar /dockerdemo-0.0.1-SNAPSHOT.jar
 ---> Running in 7a3cdc1d112b
 ---> 1f800bf8cb24
Removing intermediate container 7a3cdc1d112b
Successfully built 1f800bf8cb24
Successfully tagged microservice-eureka-demo:latest
[INFO] Built microservice-eureka-demo
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 39.982 s
[INFO] Finished at: 2017-07-23T21:51:21+08:00
[INFO] Final Memory: 42M/393M
[INFO] ------------------------------------------------------------------------

7.ssh連接192.168.244.130,執(zhí)行命令“docker images”,查看可用的鏡像:

root@ubuntu-02:~# docker images
REPOSITORY                                                           TAG                 IMAGE ID            CREATED             SIZE
microservice-eureka-demo                                             latest              1f800bf8cb24        23 minutes ago      658MB

8.執(zhí)行命令“docker run -p 8080:8080 microservice-eureka-demo:latest”,使用鏡像microservice-eureka-demo:latest啟動(dòng)docker容器。

root@ubuntu-02:~# docker run -p 8080:8080 microservice-eureka-demo:latest

  .   ____          _            __ _ _
 / / ___"_ __ _ _(_)_ __  __ _    
( ( )\___ | "_ | "_| | "_ / _` |    
 /  ___)| |_)| | | | | || (_| |  ) ) ) )
  "  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.4.RELEASE)

2017-07-23 14:19:21.766  INFO 1 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication v0.0.1-SNAPSHOT on 656842f890d3 with PID 1 (/dockerdemo-0.0.1-SNAPSHOT.jar started by root in /)
2017-07-23 14:19:21.792  INFO 1 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2017-07-23 14:19:22.402  INFO 1 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5a2e4553: startup date [Sun Jul 23 14:19:22 UTC 2017]; root of context hierarchy
2017-07-23 14:19:31.950  INFO 1 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-07-23 14:19:32.015  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2017-07-23 14:19:32.032  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.15
2017-07-23 14:19:32.467  INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-07-23 14:19:32.467  INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 10082 ms
2017-07-23 14:19:33.101  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: "dispatcherServlet" to [/]
2017-07-23 14:19:33.141  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: "characterEncodingFilter" to: [/*]
2017-07-23 14:19:33.148  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: "hiddenHttpMethodFilter" to: [/*]
2017-07-23 14:19:33.161  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: "httpPutFormContentFilter" to: [/*]
2017-07-23 14:19:33.161  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: "requestContextFilter" to: [/*]
2017-07-23 14:19:34.708  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5a2e4553: startup date [Sun Jul 23 14:19:22 UTC 2017]; root of context hierarchy
2017-07-23 14:19:35.105  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/phone]}" onto public java.lang.String com.example.demo.controller.Application.index()
2017-07-23 14:19:35.127  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-07-23 14:19:35.138  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-07-23 14:19:35.277  INFO 1 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-07-23 14:19:35.285  INFO 1 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-07-23 14:19:35.466  INFO 1 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-07-23 14:19:36.180  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-07-23 14:19:36.449  INFO 1 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-07-23 14:19:36.477  INFO 1 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 17.363 seconds (JVM running for 19.474)

9.執(zhí)行命令“docker ps”,查看啟動(dòng)的docker容器。

root@ubuntu-02:~# docker ps
CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS              PORTS                    NAMES
08099bd4b8e1        microservice-eureka-demo:latest   "java -jar /docker..."   27 seconds ago      Up 26 seconds       0.0.0.0:8080->8080/tcp   upbeat_borg

10.執(zhí)行命令“docker exec -it 08099bd4b8e1 bin/bash”,進(jìn)入docker容器。

root@ubuntu-02:~# docker exec -it 08099bd4b8e1 bin/bash 
root@08099bd4b8e1:/# 

11.執(zhí)行命令“ps -ef”,可用查看到docker容器里面啟動(dòng)的進(jìn)程,即是pom.xml配置文件中配置的插件docker-maven-plugin的entryPoint,java -jar /dockerdemo-0.0.1-SNAPSHOT.jar。

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

root@08099bd4b8e1:/# ps -ef
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  4 14:20 ?        00:00:17 java -jar /dockerdemo-0.0.1-SNAPSHOT.jar
root         34      0  0 14:24 ?        00:00:00 bin/bash
root         41     34  0 14:26 ?        00:00:00 ps -ef
root@08099bd4b8e1:/#

12.至此,使用docker插件構(gòu)建docker鏡像并運(yùn)行docker容器完成,訪問(wèn)路徑“http://192.168.244.130:8080/p...”,獲得controller結(jié)果:

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/67462.html

相關(guān)文章

  • 使用docker Maven插件本地構(gòu)建docker鏡像發(fā)布遠(yuǎn)程務(wù)器

    摘要:登錄網(wǎng)站,生成一個(gè)基本的應(yīng)用。將應(yīng)用導(dǎo)入并創(chuàng)建類(lèi)。連接,執(zhí)行命令,查看可用的鏡像執(zhí)行命令,使用鏡像啟動(dòng)容器。至此,使用插件構(gòu)建鏡像并運(yùn)行容器完成,訪問(wèn)路徑,獲得結(jié)果 1.登錄網(wǎng)站https://start.spring.io/,生成一個(gè)基本的SpringBoot應(yīng)用。 2.將應(yīng)用導(dǎo)入Eclipse IDE并創(chuàng)建Application類(lèi)。目錄結(jié)構(gòu)如下: showImg(https://s...

    jcc 評(píng)論0 收藏0
  • Jenkins集成Docker鏡像實(shí)現(xiàn)自動(dòng)發(fā)布

    摘要:集群環(huán)境的部署方式使用集群管理工具通過(guò)版本新增文件實(shí)現(xiàn)滾動(dòng)升級(jí)容器等同于應(yīng)用的部署 1. 思路&流程 Jenkins集成Docker鏡像實(shí)現(xiàn)自動(dòng)發(fā)布與Jenkins發(fā)布mavne項(xiàng)目思路一樣總體流程 為:Jenkins 拉去遠(yuǎn)端源碼 —— gitl實(shí)現(xiàn)應(yīng)用打包 —— jenkins本地把應(yīng)用程序打包進(jìn)Docker鏡像 ...

    defcon 評(píng)論0 收藏0
  • 解放雙手 | Jenkins + gitlab + maven 自動(dòng)打包部署項(xiàng)目

    摘要:什么是可以簡(jiǎn)單地理解為可以代替你實(shí)現(xiàn)自動(dòng)從拉取代碼,打包,部署到遠(yuǎn)程服務(wù)器的工具。隨后登錄后發(fā)現(xiàn)頁(yè)面空白,沒(méi)找到具體原因,重啟下容器后再登錄就好了。主要是配置訪問(wèn)服務(wù)器拉取代碼,還有配置遠(yuǎn)程服務(wù)器地址,目的是為了打包后上傳文件到遠(yuǎn)程服務(wù)器。 showImg(https://segmentfault.com/img/remote/1460000017907307?w=495&h=300)...

    JouyPub 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

Thanatos

|高級(jí)講師

TA的文章

閱讀更多
最新活動(dòng)
閱讀需要支付1元查看
<