一、搭建springBootAdmin服务
SpringBootAdmin 监控
<?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" 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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.0.RELEASE</version> </parent> <groupId>com.nblhtech</groupId> <artifactId>swh-monitor</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> <name>swh-monitor</name> <description>swh-monitor</description> <properties> <!-- 工程参数 --> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <!-- 依赖服务 --> <dependencies> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>2.2.1</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>2.2.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!--fork : 如果没有该项配置,devtools不会起作用,即应用不会restart --> <fork>true</fork> </configuration> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <configuration> <encoding>utf-8</encoding> <!-- 由于${}方式会被maven处理。如果你pom继承了spring-boot-starter-parent,Spring Boot已经将maven-resources-plugins默认的${}方式改为了@@方式,如@name@ useDefaultDelimiter为true则使用默认的${}方式读取maven的设置 --> <useDefaultDelimiters>true</useDefaultDelimiters> </configuration> </plugin> </plugins> </build> </project>
package monitor; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.Configuration; import de.codecentric.boot.admin.server.config.EnableAdminServer; @Configuration @EnableAutoConfiguration @EnableAdminServer public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
application.yml
server:
port: 8888
二、添加Dockerfile文件
# Docker image for springboot file run # VERSION 0.0.1 # Author: eangulee # 基础镜像使用java FROM java:8 # 作者 MAINTAINER eangulee <eangulee@gmail.com> # VOLUME 指定了临时文件目录为/tmp。 # 其效果是在主机 /var/lib/docker 目录下创建了一个临时文件,并链接到容器的/tmp VOLUME /tmp # 将jar包添加到容器中并更名为app.jar ADD demo-0.0.1-SNAPSHOT.jar app.jar # 运行jar包 RUN bash -c 'touch /app.jar' ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
三、docker编译镜像
docker build -t springbootdemo4docker .
docker images
四、启动服务
docker run -d -p 8888:8888 --name=springbootadmin springbootdemo4docker