Goal: Package SpringBoot into docker and deploy it successfully

1. Package Springboot by removing the third-party JAR package (I did not remove the third-party JAR package before, but found that the package was too large, and the third-party JAR package would not be updated frequently after the stabilization of the project later, so I packaged it in this way)
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <fork>true</fork><! <includes><! <include> <groupId> <artifactId>nothing</artifactId> </include> </includes> </configuration> </plugin> <plugin> <! GroupId >org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId>  <executions> <execution> <id>lib</id> <phase>prepare-package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
                <includeScope>compile</includeScope>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass> Springboot main classpath </mainClass> </manifest> </archive> </configuration> </plugin>Copy the code
Dockerfile is used to create a centos image configured with Java environment.
FROM centos Build based on centos image
EXPOSE 8888:8080 Map docker port 8080 to host port 8888
ADD jdk /usr/local/ Add the prepared JDK package to the specified location in the container
ENV JAVA_HOME /usr/local/jdk Configure the JAVA_HOME environment variable
ENV PATH $PATH:$JAVA_HOME/bin Configure JAVA_HOME into the PATH environment variable
ADD test.jar /home/  Add the SpringBoot JAR package to the specified location of the container
RUN /bin/bash -c 'source /etc/profile; echo $JAVA_HOME' Execute the command to effect the environment variable
WORKDIR /home # Change the working path
ENTRYPOINT ["java"."-jar"."test.jar"] Run the JAR package after the container starts
Copy the code
3. Run the command to create an image. After the image is successfully constructed, run the command to start a container
docker build -t xxx
docker run -d --name xxx -p 8888:8080 -v /home:/home xxx
Copy the code