使用docker部署springboot应用

摘要:
dockerfile同目录下建立tar目录,并复制docker-spring-boot-0.0.1-SNAPSHOT.jar文件到tar目录。

1、构造Dockerfile打包文件

#from base image centos
FROM centos
 
#MAINTAINER lirenqing
 
#Java Version#ENV JAVA_VERSION_MAJOR 7#ENV JAVA_VERSION_MINOR 60#ENV JAVA_PACKAGE       jdk
 
#install java
RUN yum -y install java

#inatall app 
ADD tar /usr/project/
 
#start app
ENTRYPOINT ["java" ,"-jar","/usr/project/docker-spring-boot-0.0.1-SNAPSHOT.jar"]

2、构建app部署文件路径

根据Dockerfile文件中定义的,app需要放置到tar目录下。dockerfile同目录下建立tar目录,并复制docker-spring-boot-0.0.1-SNAPSHOT.jar文件到tar目录。

3、制作docker镜像

➜  docker$: docker build -t lirenqing/springboot .
Sending build context to Docker daemon 416.4MB
Step 1: FROM centos
 --->67591570dd29
Step 2 : ADD tar /usr/project/
 --->Using cache
 --->6953cdf7e647
Step 3 : RUN yum -y install java
 --->Using cache
 --->24307a233aff
Step 4 : ENTRYPOINT java -jar /usr/project/docker-spring-boot-0.0.1-SNAPSHOT.jar
 --->Using cache
 --->1d32b755d223
Successfully built 1d32b755d223

4、运行docker image

➜  docker$: docker run -p 8082:8081 lirenqing/springboot
2017-01-10 19:06:38.862  INFO 1 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@deb6432: startup date [Tue Jan 10 19:06:38 UTC 2017]; root of context hierarchy
2017-01-10 19:06:39.805  INFO 1 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported forautowiring
2017-01-10 19:06:39.908  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$8b13d9ad] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

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

2017-01-10 19:06:40.659  INFO 1 --- [           main] com.example.DockerSpringBootApplication  : No active profile set, falling back to default profiles: default
2017-01-10 19:06:40.726  INFO 1 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@51565ec2: startup date [Tue Jan 10 19:06:40 UTC 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@deb6432
2017-01-10 19:06:42.960  WARN 1 --- [           main] o.s.c.a.ConfigurationClassPostProcessor  : Cannot enhance @Configuration bean definition 'refreshScope' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor returntype: Consider declaring such methods as 'static'.
2017-01-10 19:06:43.297  INFO 1 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=99495abd-c419-3697-8a34-170d1b24e479
2017-01-10 19:06:43.519  INFO 1 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported forautowiring
2017-01-10 19:06:43.840  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$8b13d9ad] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-10 19:06:44.676  INFO 1 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8081(http)
2017-01-10 19:06:44.723  INFO 1 ---[           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-01-10 19:06:44.731  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.6
2017-01-10 19:06:44.971  INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-01-10 19:06:44.973  INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4247ms
2017-01-10 19:06:45.569  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-01-10 19:06:45.581  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'metricsFilter' to: [/*]
2017-01-10 19:06:45.582  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-01-10 19:06:45.584  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-01-10 19:06:45.585  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-01-10 19:06:45.589  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-01-10 19:06:45.590  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2017-01-10 19:06:45.591  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'applicationContextIdFilter' to: [/*]
2017-01-10 19:06:46.594  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@51565ec2: startup date [Tue Jan 10 19:06:40 UTC 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@deb6432
2017-01-10 19:06:47.111  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello]}"onto public java.lang.String com.example.DockerSpringBootApplication.hell()
2017-01-10 19:06:47.124  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-01-10 19:06:47.132  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>>org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-01-10 19:06:47.225  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-01-10 19:06:47.225  INFO 1 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-01-10 19:06:47.391  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-01-10 19:06:49.669  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2017-01-10 19:06:49.670  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-01-10 19:06:49.673  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/info || /info.json],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-01-10 19:06:49.677  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/pause || /pause.json],methods=[POST]}"onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
2017-01-10 19:06:49.678  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/health || /health.json],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(java.security.Principal)
2017-01-10 19:06:49.681  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/mappings || /mappings.json],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-01-10 19:06:49.685  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-01-10 19:06:49.687  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-01-10 19:06:49.696  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/archaius || /archaius.json],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-01-10 19:06:49.698  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env],methods=[POST]}" onto public java.lang.Object org.springframework.cloud.context.environment.EnvironmentManagerMvcEndpoint.value(java.util.Map<java.lang.String, java.lang.String>)
2017-01-10 19:06:49.699  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env/reset],methods=[POST]}" onto public java.util.Map<java.lang.String, java.lang.Object>org.springframework.cloud.context.environment.EnvironmentManagerMvcEndpoint.reset()
2017-01-10 19:06:49.701  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/restart || /restart.json],methods=[POST]}"onto public java.lang.Object org.springframework.cloud.context.restart.RestartMvcEndpoint.invoke()
2017-01-10 19:06:49.709  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-01-10 19:06:49.710  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/heapdump || /heapdump.json],methods=[GET],produces=[application/octet-stream]}"onto public void org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint.invoke(boolean,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException
2017-01-10 19:06:49.724  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/features || /features.json],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-01-10 19:06:49.727  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env/{name:.*}],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
2017-01-10 19:06:49.728  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env || /env.json],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-01-10 19:06:49.735  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/resume || /resume.json],methods=[POST]}"onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
2017-01-10 19:06:49.738  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-01-10 19:06:49.741  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/json]}"onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2017-01-10 19:06:49.743  INFO 1 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/refresh || /refresh.json],methods=[POST]}"onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
2017-01-10 19:06:50.094  INFO 1 --- [           main] o.s.ui.freemarker.SpringTemplateLoader   : SpringTemplateLoader for FreeMarker: using resource loader [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@51565ec2: startup date [Tue Jan 10 19:06:40 UTC 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@deb6432] and template loader path [classpath:/templates/]
2017-01-10 19:06:50.103  INFO 1 --- [           main] o.s.w.s.v.f.FreeMarkerConfigurer         : ClassTemplateLoader forSpring macros added to FreeMarker configuration
2017-01-10 19:06:50.358  WARN 1 ---[           main] o.s.c.n.a.ArchaiusAutoConfiguration      : No spring.application.name found, defaulting to 'application'
2017-01-10 19:06:50.372  WARN 1 ---[           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2017-01-10 19:06:50.372  INFO 1 ---[           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2017-01-10 19:06:50.391  WARN 1 ---[           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2017-01-10 19:06:50.396  INFO 1 ---[           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2017-01-10 19:06:50.569  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans forJMX exposure on startup
2017-01-10 19:06:50.601  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'refreshScope' has been autodetected forJMX exposure
2017-01-10 19:06:50.603  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'environmentManager' has been autodetected forJMX exposure
2017-01-10 19:06:50.608  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'configurationPropertiesRebinder' has been autodetected forJMX exposure
2017-01-10 19:06:50.611  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'refreshEndpoint' has been autodetected forJMX exposure
2017-01-10 19:06:50.613  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'restartEndpoint' has been autodetected forJMX exposure
2017-01-10 19:06:50.622  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'environmentManager': registering with JMX server as MBean [org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager]
2017-01-10 19:06:50.655  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'restartEndpoint': registering with JMX server as MBean [org.springframework.cloud.context.restart:name=restartEndpoint,type=RestartEndpoint]
2017-01-10 19:06:50.700  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'refreshScope': registering with JMX server as MBean [org.springframework.cloud.context.scope.refresh:name=refreshScope,type=RefreshScope]
2017-01-10 19:06:50.728  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'configurationPropertiesRebinder': registering with JMX server as MBean [org.springframework.cloud.context.properties:name=configurationPropertiesRebinder,context=51565ec2,type=ConfigurationPropertiesRebinder]
2017-01-10 19:06:50.757  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'refreshEndpoint': registering with JMX server as MBean [org.springframework.cloud.endpoint:name=refreshEndpoint,type=RefreshEndpoint]
2017-01-10 19:06:50.964  INFO 1 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2017-01-10 19:06:51.157  INFO 1 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8081(http)
2017-01-10 19:06:51.166  INFO 1 --- [           main] com.example.DockerSpringBootApplication  : Started DockerSpringBootApplication in 14.798 seconds (JVM running for 16.392)

当看到上面信息,证明已经运行成功了。可以直接访问localhost:8082即可访问构建的springboot应用了。

注:

本次构建由于网络原因,使用docker默认的镜像仓库下载经常出错,本次采用国内镜像网站下载。镜像代理设置可以访问:daodocker.io,需要注册一个帐号后有配置说明,参照配置说明配置即可。

免责声明:文章转载自《使用docker部署springboot应用》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇zuul简单使用System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Tapestry5之onActivate和onPassivate

T5有三种类型的事件,分别是EventLink,ActionLink,Form。并且前两种是通过HTTP GET从服务器获得信息的,最后一种是通过HTTP POST获得信息的。 还有一点儿很重要的就是EventLink和ActionLink从服务器端获得想要的信息的方式是:GET/REDIRECT/GET。FORM的方式是:POST/REDIRECT/GET...

Greenplum-cc-web监控软件安装

一环境列表 操作系统centos6.5 64 Greenplum版本: greenplum-db-4.3.5.3-build-2-RHEL5-x86_64.tar Greenplum集群环境搭建:参考http://blog.csdn.net/sunziyue/article/details/49026913 需求:在已经搭建的集群环境中安装Greenpl...

MySQL高可用方案--MHA部署及故障转移

架构设计及必要配置 主机环境 IP                 主机名             担任角色 192.168.192.128  node_master    MySQL-Master| MHA-Node 192.168.192.129  node_slave     MySQL-Slave | MHA-Node(备选Master) 19...

设计模式--观察者模式初探和java Observable模式

初步认识观察者模式  观察者模式又称为发布/订阅(Publish/Subscribe)模式,因此我们可以用报纸期刊的订阅来形象的说明:     报社方负责出版报纸.     你订阅了该报社的报纸,那么只要报社发布了新报纸,就会通知你,或发到你手上.     如果你不想再读报纸,可以取消订阅,这样,报社发布了新报纸就不会再通知你.   理解其实以上的概念,就...

OVF and OVA

最近测试的东西有关于ovf 和ova等相关用例,在网上找了点内容摘抄了下来。 一、什么是OVF文件 开源虚拟化格式OVF文件是一种开源的文件规范,它描述了一个开源、安全、有效、可拓展的便携式虚拟打包以及软件分布格式,它一般有几个部分组成,分别是ovf文件、mf文件、cert文件、vmdk文件和iso文件。 二、OVF文件工作原理以及各组件的作用...

FFmpeg在Linux下编译使用

1.FFmpeg编译 1.1.安装yasm 这里我是直接通过ubuntu包安装的,当然也可以通过编译源码来安装。 sudo apt-get install yasm 1.2.下载FFmpeg git clone https://git.ffmpeg.org/ffmpeg.git 1.3.配置、编译FFMPEG ./configure --prefix=ho...