** Original ** ------ -----
docker now use more and more, but then also install multiple containers one by one, more trouble. Compared to k8s of "heavy", docker-compose relatively much simpler. Here is a use docker-compose, applications for spring boot a cluster (two docker) process released.
1. Introduction
Architecture: spring boot using nginx as a reverse proxy, redis as a cache, mysql as the database, all of the docker.
Environment: developed using win 10 notebooks, eclipse ide, maven of this is that we usually use. Of course, the idea is also useful.
Publishing environment: a ecs Baidu cloud 1 nuclear 2G centos 7.x
Benpian is the first part, mainly spring boot applications. The second part look at this
small application 2. spring boot of
general, spring boot application will be used redis, mysql.
In the present embodiment the counter as a redis api call, mysql a table, and stores docker-compose command description (section, to provide data for the boot application is the main function)
good, the first item to the structure of FIG.
Then directly on the various code:
1) pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>ex.dockercompose</groupId> <artifactId>compose-demo</artifactId> <version>1.0</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.1.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> <mainClass>ex.dockercompose.DemoApplication</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
2) DemoApplication.java
3) RedisConfig.java
4) CommandController.java
5) RedisController.java
6) CommandDao.java
7) CommandService.java
8) application-compose.yml
9) application-dev.yml
10) application.yml
11) build.bat
12) compose.sql
13) Docker-compose.yml
14) Dockerfile
15) nginx.conf
3. Test
4. Package
in order to
Well herein, this is basically a boot-related applications. Related part docker explained in the second part.