简体   繁体   中英

How to create docker image in Spring Boot project

I have tried using spotify/docker-maven-plugin without any success.

Below is part of my pom.xml file

<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>${dockerfile-maven-version}</version>
  <executions>
    <execution>
      <id>default</id>
      <goals>
        <goal>build</goal>
        <goal>push</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <repository>myrepo/maven-docker-spotify</repository>
    <tag>${project.version}</tag>
    <buildArgs>
      <JAR_FILE>${project.build.finalName}-jar-with-dependencies.jar</JAR_FILE>
    </buildArgs>
  </configuration>
</plugin>

The spotify/docker-maven-plugin you are using is currently inactive. It's recommended using spotify/dockerfile-maven-plugin instead.

So change the plugin section of your pom.xml file to resemble below

<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>dockerfile-maven-plugin</artifactId>
  <version>${dockerfile-maven-version}</version>
  <executions>
    <execution>
      <id>default</id>
      <goals>
        <goal>build</goal>
        <goal>push</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <repository>spotify/foobar</repository>
    <tag>${project.version}</tag>
    <buildArgs>
      <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
    </buildArgs>
  </configuration>
</plugin>

Note: You can also try using JIB maven plugin that doesnt require you to have docker installed and works with minimal configuration. With JIB, Running below command in is enough to do the jo

mvn compile com.google.cloud.tools:jib-maven-plugin:0.9.2:dockerBuild

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM