Foreword
I have written an article about "Docker-compose Deploying Jar Package Service" before. Interested partners can click the link to view.
But many times, the service will also be deployed as a war package, so what should I do? The following is a record of my deployment of war process, still encountered a lot of pits. Make a record here.
Project renovation
- The startup class inherits SpringBootServletInitializer and overrides the configure method.
/**
* 开放平台启动类
*
* @author gourd.hu
*/
@SpringBootApplication
@Slf4j
public class OpenapiWebApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(OpenapiWebApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(OpenapiWebApplication.class, args);
log.warn(">o< 开放平台服务启动成功!温馨提示:代码千万行,注释第一行,命名不规范,同事泪两行 >o<");
}
}
- pom modify package type
<packaging>war</packaging>
- Package plugin configuration
<build>
<!--自定义打包文件名-->
<finalName>openapi</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<!--启动类路径-->
<mainClass>org.gourd.hu.OpenapiWebApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
- Package with maven- package command
deploy
- docker-compose.yml preparation, here is my configuration
version: '3'
services:
openapi-service:
image: tomcat:9.0.33
ports:
- "8088:8080"
restart: always
environment:
- TZ=Asia/Shanghai
- JAVA_OPTS=-Xmx256m -Xms256m
entrypoint:
- "catalina.sh"
- "run"
volumes:
- "./tomcat-web/webapps:/usr/local/tomcat/webapps"
- "./tomcat-web/logs:/usr/local/tomcat/logs"
container_name: openapi
- Put the war package under / tomcat-web / webapps
- Run to the docker-compose.yml directory and execute the command
docker-compose up -d
Conclusion
The deployment of the war package by docker-compose is completed. You can view the startup log in the logs directory. If there is anything wrong with this article, please correct me. Finally present your own open source project, interested friends can download and see.
cloud-plus: https://blog.csdn.net/HXNLYW/article/details/104635673