• Create a Dockerfile file in the root directory of the Maven module you want to run
FROM openjdk:8-jdk-alpine
MAINTAINER xiaodx
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
VOLUME /logs
ARG JAR_FILE=target/cxs-yunying.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java"."-jar"."/app.jar"]

Copy the code
  • Add the following two Maven plug-ins to the POM.xml of the Maven module you want to run
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <! - the docker maven plug-in, website: https://github.com/spotify/docker ‐ maven ‐ plugin - > <! -- Dockerfile maven plugin --> <plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>1.4.10</version> <executions> <id>default</id> <goals>! Executions --> <goal>build</goal> <goal>push</goal> </execution> </executions> <configuration> <! <username>xiaodx</username> <password>Dc123456</password>${docker.registry}/${docker.image.prefix}/${project.artifactId}</repository>
		<tag>${project.version}</tag>
		<buildArgs>
			<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
		</buildArgs>
	</configuration>
</plugin>
Copy the code
  • Run maven to automatically generate images and upload them to the local Docker host.
mvn install -Dmaven.test.skip=true
Copy the code
  • Upload the image to Harbor: Run the following plugin in Maven to upload the image to Harbor