docker部署spring boot项目在服务器上

IDE:idea

工具:docker

spring boot:2.0.1

========================================

简单记录一下流程,以供参考:

第一步:首先得有一个spring boot的项目【集成了jpa+mybatis的spring boot 例子:https://github.com/AngelSXD/swapping

第二步:项目打包为jar包

install成功以后

找到项目根目录下的target目录,这里面的jar就是打包好可以部署的jar包

第三步:准备服务器和其他的环境,例如mysql数据库,docker

  进入服务器,【centOS7上安装docker步骤:https://www.cnblogs.com/sxdcgaq8080/p/9178918.html

  如果你想在服务器上安装mysql,步骤如下:【https://www.cnblogs.com/sxdcgaq8080/p/9199406.html

  【当然,你打包的jar包中,配置文件中连接的数据库的地址需要是你mysql的实际地址,否则数据库连接不上】

第四步:准备服务器上的jar包存放目录以及Dockerfile文件

  进入服务器,创建你jar包上传到服务器要放的目录,例如:【在linux上创建目录的命令自己查!!】

  我要将jar包即将放在这个目录下:

并且在本目录下创建Dockerfile文件,并且将下面这段粘贴在Dockerfile文件中【使用vi命令即可完成文件的创建以及文件内容的填充】

FROM java:8
VOLUME /temp
ADD swapping.jar swapping.jar
RUN bash -c ‘touch /swapping.jar‘
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","-Xmx1024m","-Xms1024m","/swapping.jar"]

对于文件内容的解释:【Dockerfile命令解释:http://www.docker.org.cn/dockerppt/114.html

FROM java:8

指定要构建的spring boot服务镜像的基础源镜像是java,版本是8;如果本地没有java:8的镜像,就会从dockerHub下载。一般首次下载,以后就不会下载了。
VOLUME /temp

VOLUME 指向了容器内的/tmp的目录,由于 Spring Boot 使用内置的Tomcat容器,Tomcat 默认使用/tmp作为工作目录。这个命令的效果是:在宿主机的/var/lib/docker目录下创建一个临时文件并把它链接到容器中的/tmp目录

VOLUME 命令只能指定挂载点,也就是说在此处,只能指定容器内的目录,不能指定宿主机上对应的目录,也就是说是宿主机上自动生成的目录 去挂载了  容器内的指定的/tmp目录!!!
如果想要指定宿主机的目录去进行挂载,只能通过run命令中的 -v参数进行 宿主机的指定目录 挂载  容器内的指定目录
ADD swapping.jar swapping.jar

其实就是 ADD 【rz上传上来的文件】 【要被拷贝到即将要构建的docker容器中的文件】
RUN bash -c ‘touch /swapping.jar‘

实际执行复制操作的命令
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","-Xmx1024m","-Xms1024m","/swapping.jar"]

ENTRYPOINT 配置容器启动后执行的命令,并且不可被 docker run 提供的参数覆盖。

-Djava.security.egd=file:/dev/./urandom
添加java.security.egd的系统属性指向/dev/urandom,JVM上的随机数与熵池策略
参考地址:【https://blog.csdn.net/lanmo555/article/details/51909021】

第五步:上传jar包

先修改jar包名字:修改为swapping.jar【文件名需要与Dockerfile文件中配置的一致】

  使用命令 rz

注意,

#Dockerfile和jar包放在同一个目录下

第六步:需要进入jar包所在目录,使用jar包创建镜像

  命令如下:【注意有点哦】

docker build -t swapping .

第七步:运行镜像,启动docker容器

  最简单的运行命令

docker run --name swapping -itd --net=host  swapping 

需要注意spring boot项目的时区问题的启动命令【关于时区处理问题,需要参考:https://www.cnblogs.com/sxdcgaq8080/p/10057385.html

  需要注意spring boot项目启动开发配置文件和生产配置文件的配置文件的启动应用【https://www.cnblogs.com/sxdcgaq8080/p/10481974.html

docker run --name swapping -itd --net=host -v /etc/localtime:/etc/localtime:ro  -v /etc/timezone:/etc/timezone:ro  swapping

启动成功后:查看容器启动情况

docker logs -f swapping

退出日志查看 使用

Ctrl+Z

查看启动运行日志如下:

[email protected]:/soft/java/dockerJar/swapping# docker logs -f swapping

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

2018-12-03 10:25:38.055  INFO 1 --- [           main] com.sxd.swapping.SwappingApplication     : Starting SwappingApplication v0.0.1-SNAPSHOT on wj.luna.base with PID 1 (/swapping.jar started by root in /)
2018-12-03 10:25:38.060  INFO 1 --- [           main] com.sxd.swapping.SwappingApplication     : No active profile set, falling back to default profiles: default
2018-12-03 10:25:38.257  INFO 1 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.ser[email protected]1ef7fe8e: startup date [Mon Dec 03 10:25:38 CST 2018]; root of context hierarchy
2018-12-03 10:25:41.232  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-12-03 10:25:41.429  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2018-12-03 10:25:41.452  INFO 1 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.sxd.swapping.dao.jpa.GoodsStockDao.
2018-12-03 10:25:41.455  INFO 1 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.sxd.swapping.dao.jpa.HuaYangAreaDao.
2018-12-03 10:25:42.341  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean ‘org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration‘ of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$3b883049] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-12-03 10:25:43.196  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9666 (http)
2018-12-03 10:25:43.243  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-12-03 10:25:43.243  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.29
2018-12-03 10:25:43.270  INFO 1 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib]
2018-12-03 10:25:43.528  INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-12-03 10:25:43.529  INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 5277 ms
2018-12-03 10:25:44.010  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet statViewServlet mapped to [/druid/*]
2018-12-03 10:25:44.013  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-12-03 10:25:44.020  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘characterEncodingFilter‘ to: [/*]
2018-12-03 10:25:44.020  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘hiddenHttpMethodFilter‘ to: [/*]
2018-12-03 10:25:44.021  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘httpPutFormContentFilter‘ to: [/*]
2018-12-03 10:25:44.021  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘requestContextFilter‘ to: [/*]
2018-12-03 10:25:44.021  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: ‘webStatFilter‘ to urls: [/*]
2018-12-03 10:25:44.616  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit ‘default‘
2018-12-03 10:25:44.664  INFO 1 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2018-12-03 10:25:44.874  INFO 1 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.2.16.Final}
2018-12-03 10:25:44.878  INFO 1 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2018-12-03 10:25:44.982  INFO 1 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
DEBUG - {conn-10001} connected
DEBUG - {conn-10002} connected
DEBUG - {conn-10003} connected
DEBUG - {conn-10004} connected
DEBUG - {conn-10005} connected
2018-12-03 10:25:45.859  INFO 1 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited
DEBUG - {conn-10005} pool-connect
2018-12-03 10:25:45.890  INFO 1 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL55Dialect
DEBUG - {conn-10005} pool-recycle
DEBUG - {conn-10005} pool-connect
DEBUG - {conn-10005} pool-recycle
2018-12-03 10:25:46.948  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit ‘default‘
2018-12-03 10:25:47.626  INFO 1 --- [           main] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
2018-12-03 10:25:50.730  WARN 1 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2018-12-03 10:25:50.872  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayang/pages],methods=[GET]}" onto public com.sxd.swapping.base.PageResponse<com.sxd.swapping.domain.HuaYangArea> com.sxd.swapping.controller.HuaYangApiWithJPA.pages(com.sxd.swapping.domain.HuaYangArea)
2018-12-03 10:25:50.874  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayang],methods=[POST]}" onto public com.sxd.swapping.base.UniVerResponse<com.sxd.swapping.domain.HuaYangArea> com.sxd.swapping.controller.HuaYangApiWithJPA.huayang(com.sxd.swapping.domain.HuaYangArea)
2018-12-03 10:25:50.874  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayang/huayangs],methods=[GET]}" onto public com.sxd.swapping.base.UniVerResponse<java.util.List<com.sxd.swapping.domain.HuaYangArea>> com.sxd.swapping.controller.HuaYangApiWithJPA.huayangs(java.lang.String)
2018-12-03 10:25:50.875  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayang/updates],methods=[POST]}" onto public com.sxd.swapping.base.UniVerResponse<java.util.List<com.sxd.swapping.domain.HuaYangArea>> com.sxd.swapping.controller.HuaYangApiWithJPA.updates(com.sxd.swapping.base.BatchBean)
2018-12-03 10:25:50.875  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayang/update],methods=[PUT]}" onto public com.sxd.swapping.base.UniVerResponse<com.sxd.swapping.domain.HuaYangArea> com.sxd.swapping.controller.HuaYangApiWithJPA.update(com.sxd.swapping.domain.HuaYangArea)
2018-12-03 10:25:50.895  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayangMybatis/oneHuaYang],methods=[GET]}" onto public com.sxd.swapping.base.UniVerResponse<com.sxd.swapping.domain.HuaYangArea> com.sxd.swapping.controller.HuaYangApiWithMyBatis.findOne(java.lang.String)
2018-12-03 10:25:50.900  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayangMybatis/findMap],methods=[GET]}" onto public com.sxd.swapping.base.UniVerResponse<java.util.Map<java.lang.String, java.lang.String>> com.sxd.swapping.controller.HuaYangApiWithMyBatis.findMap(com.sxd.swapping.domain.HuaYangArea)
2018-12-03 10:25:50.900  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayangMybatis/findBy3],methods=[GET]}" onto public com.sxd.swapping.base.UniVerResponse<java.util.List<com.sxd.swapping.base.HuaYangModelBean>> com.sxd.swapping.controller.HuaYangApiWithMyBatis.findByNameAndPersonAndCreateDate(com.sxd.swapping.domain.HuaYangArea)
2018-12-03 10:25:50.901  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayangMybatis/findBy3Page],methods=[GET]}" onto public com.sxd.swapping.base.PageResponse<com.sxd.swapping.base.HuaYangModelBean> com.sxd.swapping.controller.HuaYangApiWithMyBatis.findByNameAndPersonAndCreateDatePage(com.sxd.swapping.domain.HuaYangArea)
2018-12-03 10:25:50.902  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayangMybatis/findByNameLike],methods=[GET]}" onto public com.sxd.swapping.base.UniVerResponse<java.util.List<com.sxd.swapping.domain.HuaYangArea>> com.sxd.swapping.controller.HuaYangApiWithMyBatis.findAll1(java.lang.String)
2018-12-03 10:25:50.904  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayangMybatis/findByNameLike2],methods=[GET]}" onto public com.sxd.swapping.base.UniVerResponse<java.util.List<com.sxd.swapping.domain.HuaYangArea>> com.sxd.swapping.controller.HuaYangApiWithMyBatis.findAll2(java.lang.String)
2018-12-03 10:25:50.912  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayangMybatis/oneHuaYang],methods=[DELETE]}" onto public com.sxd.swapping.base.UniVerResponse<java.lang.String> com.sxd.swapping.controller.HuaYangApiWithMyBatis.deleteOne(java.lang.Long)
2018-12-03 10:25:50.913  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayangMybatis/update],methods=[PUT]}" onto public com.sxd.swapping.base.UniVerResponse<com.sxd.swapping.domain.HuaYangArea> com.sxd.swapping.controller.HuaYangApiWithMyBatis.update(com.sxd.swapping.domain.HuaYangArea)
2018-12-03 10:25:50.913  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/huayangMybatis/insert],methods=[POST]}" onto public com.sxd.swapping.base.UniVerResponse<com.sxd.swapping.domain.HuaYangArea> com.sxd.swapping.controller.HuaYangApiWithMyBatis.insert(com.sxd.swapping.domain.HuaYangArea)
2018-12-03 10:25:50.914  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/goods/stock/concurrentStock],methods=[POST]}" onto public com.sxd.swapping.base.UniVerResponse<java.util.Map<java.lang.Integer, java.lang.String>> com.sxd.swapping.controller.GoodsStockController.concurrentStock(com.sxd.swapping.domain.GoodsStock)
2018-12-03 10:25:50.917  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/goods/stock/insert],methods=[POST]}" onto public com.sxd.swapping.base.UniVerResponse<com.sxd.swapping.domain.GoodsStock> com.sxd.swapping.controller.GoodsStockController.insert(com.sxd.swapping.domain.GoodsStock)
2018-12-03 10:25:50.919  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/createCode/getCode]}" onto public com.sxd.swapping.base.UniVerResponse<java.lang.String> com.sxd.swapping.controller.CreateCodeController.createCode()
2018-12-03 10:25:50.927  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources/configuration/ui]}" onto public org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.UiConfiguration> springfox.documentation.swagger.web.ApiResourceController.uiConfiguration()
2018-12-03 10:25:50.934  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources/configuration/security]}" onto public org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.SecurityConfiguration> springfox.documentation.swagger.web.ApiResourceController.securityConfiguration()
2018-12-03 10:25:50.935  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources]}" onto public org.springframework.http.ResponseEntity<java.util.List<springfox.documentation.swagger.web.SwaggerResource>> springfox.documentation.swagger.web.ApiResourceController.swaggerResources()
2018-12-03 10:25:50.941  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.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-12-03 10:25:50.942  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.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-12-03 10:25:51.332  INFO 1 --- [           main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [public org.springframework.http.ResponseEntity<springfox.documentation.spring.web.json.Json> springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest)]
2018-12-03 10:25:51.590  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]
2018-12-03 10:25:52.093  INFO 1 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.ser[email protected]1ef7fe8e: startup date [Mon Dec 03 10:25:38 CST 2018]; root of context hierarchy
2018-12-03 10:25:52.297  INFO 1 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-12-03 10:25:52.298  INFO 1 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-12-03 10:25:52.321  INFO 1 --- [           main] .m.m.a.ExceptionHandlerExceptionResolver : Detected @ExceptionHandler methods in myControllerAdvice
2018-12-03 10:25:53.431  INFO 1 --- [           main] o.s.ui.freemarker.SpringTemplateLoader   : SpringTemplateLoader for FreeMarker: using resource loader [org.springframework.boot.web.ser[email protected]1ef7fe8e: startup date [Mon Dec 03 10:25:38 CST 2018]; root of context hierarchy] and template loader path [classpath:/templates/]
2018-12-03 10:25:53.432  INFO 1 --- [           main] o.s.w.s.v.f.FreeMarkerConfigurer         : ClassTemplateLoader for Spring macros added to FreeMarker configuration
2018-12-03 10:25:53.485  WARN 1 --- [           main] o.s.b.a.f.FreeMarkerAutoConfiguration    : Cannot find template location(s): [classpath:/templates/] (please add some templates, check your FreeMarker configuration, or set spring.freemarker.checkTemplateLocation=false)
2018-12-03 10:25:53.998  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-12-03 10:25:54.001  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name ‘dataSource‘ has been autodetected for JMX exposure
2018-12-03 10:25:54.018  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean ‘dataSource‘: registering with JMX server as MBean [com.alibaba.druid.pool:name=dataSource,type=DruidDataSource]
2018-12-03 10:25:54.031  INFO 1 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 2147483647
2018-12-03 10:25:54.031  INFO 1 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2018-12-03 10:25:54.070  INFO 1 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2018-12-03 10:25:54.164  INFO 1 --- [           main] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references
2018-12-03 10:25:54.802  INFO 1 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: insertUsingPOST_1
2018-12-03 10:25:54.806  INFO 1 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: updateUsingPUT_1
2018-12-03 10:25:54.944  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9666 (http) with context path ‘‘
2018-12-03 10:25:54.969  INFO 1 --- [           main] com.sxd.swapping.SwappingApplication     : Started SwappingApplication in 17.782 seconds (JVM running for 18.811)

可以看到启动成功了。

第八步:访问服务看是否正常

接口返回正常

数据库存储正常

好了,服务部署完成拉!!!!!

OK,如果想要重新启动spring boot服务,可以使用命令

docker restart swapping

ok现在,如果代码更新了,想要停止服务,移除springboot服务,重新部署

分别执行如下步骤即可

停止服务

docker stop swapping

移除容器

docker rm -f swapping

移除jar包

rm -f swapping.jar

重新打包【在idea操作,注意配置文件中的连接地址等配置】

【并且注意Dockerfile文件中指定的jar包文件名,需要与上传的jar包文件名一致】

上传jar包

rz

然后重新制作镜像

docker build -t swapping .

启动服务

docker run --name swapping -itd --net=host -v /etc/localtime:/etc/localtime:ro  -v /etc/timezone:/etc/timezone:ro  swapping

即可完成重新部署!!!

当然,你之前构建的镜像文件依旧存在,虽然它不影响你项目的使用,但是你的镜像存在会占据你服务器的空间

所以可以使用命令,查看目前有哪些镜像

docker images

可以使用命令,删除不用的镜像文件

docker rmi 9d3ee8a877d3

原文地址:https://www.cnblogs.com/shanheyongmu/p/11805104.html

时间: 2024-09-29 22:14:07

docker部署spring boot项目在服务器上的相关文章

部署spring boot到tomcat服务器上

在tomcat里部署spring boot项目成功,访问:服务器地址+端口+项目名称 问题:在idea里使用tomcat部署spring boot项目,启动成功,却是访问失败? 原文地址:https://www.cnblogs.com/devin-sl/p/12108684.html

如何用Docker部署Spring Boot项目

1.idea中安装docker插件: 2.新建DockerFile,内容如下. # 基础镜像使用java FROM java:8 # 作者 MAINTAINER vic <[email protected]> # VOLUME 指定了临时文件目录为/tmp. # 其效果是在主机 /var/lib/docker 目录下创建了一个临时文件,并链接到容器的/tmp VOLUME /tmp # 将jar包添加到容器中并更名为app.jar ADD es-1.0.0-SNAPSHOT.jar app.j

在CentOS 7上安装docker,部署spring boot

一.查看linux版本:lsb_release -a (如没有这个命令,安装:yum install -y redhat-lsb) uname -r docker 在centos安装,需要centos 7以上版本. 二.docker 安装操作步骤 docker 官网 :  https://docs.docker.com/get-started 安装必要的工具:Install required packages. yum-utils provides the yum-config-manager 

Gitlab CI 集成 Kubernetes 集群部署 Spring Boot 项目

在上一篇博客中,我们成功将 Gitlab CI 部署到了 Docker 中去,成功创建了 Gitlab CI Pipline 来执行 CI/CD 任务.那么这篇文章我们更进一步,将它集成到 K8s 集群中去.这个才是我们最终的目标.众所周知,k8s 是目前最火的容器编排项目,很多公司都使用它来构建和管理自己容器集群,可以用来做机器学习训练以及 DevOps 等一系列的事情. 在这里,我们聚焦 CI/CD,针对于 Spring Boot 项目,借助 Gitlab CI 完成流水线的任务配置,最终部

【docker】docker部署spring boot服务,但是docker logs查看容器输出控制台日志,没有日志打印,日志未打印,docker logs不打印容器日志

如题: docker部署spring boot服务,但是docker logs查看容器输出控制台日志,没有日志打印,日志未打印,docker logs不打印容器日志 场景再现: docker部署并启动了  springboot服务,容器启动正常,docker exec 也可以正常进入容器内部,但是docker logs 控制台并没有日志打印出来. 同样的,/var/lib/docker/containers目录下的对应容器目录中,也没有对应的 *-json.log日志文件生成. 原因: dock

Spring Boot 2.0(六):使用 Docker 部署 Spring Boot 开源软件云收

只需三步即可部署开源项目云收藏,打造专属个人的收藏系统,就是这么简单! 云收藏项目已经开源2年多了,作为当初刚开始学习 Spring Boot 的练手项目,使用了很多当时很新的技术,现在看来其实很多新技术是没有必要使用的,但做为学习案例来讲确实是一个绝佳的 Spring Boot 实践. 从开源到现在,写了一些教程给大家介绍如何部署云收藏,如何在IDE中运行云收藏,但是仍然有很多的朋友不知道如何使用,如何部署?就像"请提供一份云收藏数据结构" 这样的问题我至少都回答了一百多次,并且在

【Tomcat】使用Tomcat部署Spring Boot项目生成的jar包

介绍 简单来说,Tomcat是一个免费的,用于Java Web应用以及其它Web应用的一个Web服务器.(简单地概括一下,可能有误) 下载与安装 本文章目标是把Spring Boot Web项目生成的jar包,放到Windows Server 2008 r2中部署 首先要自行安装JDK,本例子中使用jdk-8u172 下载Tomcat,地址https://tomcat.apache.org/ 原文地址:https://www.cnblogs.com/LiveYourLife/p/8884654.

docker 构建 spring boot项目

在docker 开始部署springBoot项目 1.在centos7 ~ 创建一个文件夹docker 里面放置 上面的Dockerfile 和 springBoot 打包的项目docker_spring_boot.jar 2. 在该docker文件下 指令:docker build -t docker . 执行docker build命令,docker就会根据Dockerfile里你定义好的命令进行构建新的镜像. -t代表要构建的镜像的tag,.代表当前目录,也就是Dockerfile所在的目

docker 部署Spring Boot:Docker化Spring Boot应用程序

第一章 1.创建项目存放目录 mkdir /root/sproot -p 2.准备好Spring Boot应用程序 jar 包 testrest.jar 第二章 1. 安装docker 在所有节点执行:   setenforce 0 iptables -F iptables -t nat -F iptables -I FORWARD -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT iptables -I INPUT -s 192.168.0.0/24 -j ACCEPT