springboot 通过docker 打包编译镜像
添加plugin
<?xml version="1.0" encoding="UTF-8"?> <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"> <parent> <artifactId>peacock</artifactId> <groupId>cn.xiaojf</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>peacock-eureka</artifactId> <properties> <docker.registry.host>192.168.1.57:5000</docker.registry.host> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>${spring-boot-admin.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.2.0</version> <configuration>
<!-- 镜像名称 --> <imageName>${docker.registry.host}/${project.artifactId}:${project.version}</imageName>
<!-- 基础镜像 --> <baseImage>java:8-jre-alpine</baseImage> <!--Dockerfile的位置 --> <!--<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>-->
<!-- 容器启动后执行命令 --> <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<!-- 复制jar包到镜像中 --> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> </plugins> </build> </project>
执行build命令
发布镜像到私有registry
查看结果
meiya@meiya:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.1.57:5000/peacock-eureka 1.0-SNAPSHOT 339ecba6521d 12 minutes ago 163MB jrebel-ls latest 4ef60f55bcc3 About an hour ago 115MB 192.168.1.57:5000/tomcat latest 27600aa3d7f1 44 hours ago 463MB tomcat latest 27600aa3d7f1 44 hours ago 463MB registry latest f32a97de94e1 2 months ago 25.8MB java 8-jre-alpine fdc893b19a14 2 years ago 108MB
查看私服
meiya@meiya:~$ curl http://localhost:5000/v2/_catalog {"repositories":["peacock-eureka","tomcat"]}