review

There are many ways to integrate SpringBoot application into Docker. The selection of technology by the author is based on the overall consideration of the team, mainly including the following aspects:

  • Continuous integration: Mainly considering the convenience and scalability of continuous integration (Jenkins is used as the continuous integration tool of the author’s team)
  • Learning cost: the main consideration is the cost of learning by the developer (writing Dockerfile)
  • Maintainability: mainly involves two maintenance work, one is the maintenance of Dockerfile file, the other is the maintenance of Docker image

Technology selection

Pure Dockerfile

  • advantages

    High flexibility, high degree of customization

    Such as:

    FROM java:8
    ENV PROFILES=default
    COPY *.jar /opt/
    ENTRYPOINT ["java"."-jar"."The target/message - 0.0.1 - the SNAPSHOT. Jar"."--spring.profiles.active=${PROFILES} "]
    Copy the code
  • disadvantages

    Developers need to know how to write Dockerfile, and Dockerfile also needs to be maintained separately.

    Unable to use project-related parameters gracefully

Docker-maven-plugin

Docker-maven-plugin is a plugin developed by Spotify team. The plugin integrates maven’s life cycle with Dockerfile. The current status of the plugin is inactive.

  • advantages

    Low learning cost, no need to know Dockerfile.

    Ability to integrate related parameters in Maven

  • disadvantages

    Poor readability and maintainability of POM code for example:

<plugin>
      <groupId>com.spotify</groupId>
      <artifactId>docker-maven-plugin</artifactId>
      <version>VERSION GOES HERE</version>
      <configuration>
        <imageName>example</imageName>
        <baseImage>java</baseImage>
        <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
        <! -- copy the service's jar file from target into the root directory of the image --> 
        <resources>
           <resource>
             <targetPath>/</targetPath>
             <directory>${project.build.directory}</directory>
             <include>${project.build.finalName}.jar</include>
           </resource>
        </resources>
      </configuration>
    </plugin>
Copy the code

Official address: Git address

Dockerfile-maven

Maven is also developed by the Spotify team, ditching the previous Don’t do anything fancy features and focusing more on the integration of Maven and Dockerfile, rather than integrating the functionality of Dockerfile into plug-ins.

  • advantages

    Return to original demand, the structure is clearer, concise and elegant.

    Easy to scale, easy to integrate, the ability to integrate Maven parameters.

  • disadvantages

    You need to know a little bit about Dockfile writing

<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>dockerfile-maven-plugin</artifactId>
  <version>${dockerfile-maven-version}</version>
  <configuration>
    <repository>spotify/foobar</repository>
    <tag>${project.version}</tag>
    <buildArgs>
      <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
    </buildArgs>
  </configuration>
</plugin>
Copy the code

Official address: Git address

Today the Lantern Festival, I wish you a happy Lantern Festival, away from the pain!

In addition, I have added two examples of plugin code to Github, please see: sample address