无法执行目标com.spotify:dockerfile-maven-plugin:1.3.6:在项目'foo'上构建:无法构建映像:

时间:2018-10-22 15:49:49

标签: java maven docker spring-boot

我们在一个由4人组成的小型团队中工作。我们使用docker部署我们的服务。其中一项服务是一个Java Spring Boot项目,该项目在使用maven构建docker映像之后进行了部署。为了制作Spring Boot服务的docker镜像,我们使用mvn clean package dockerfile:build

有趣的是,我的同事在构建Spring Boot服务的docker映像时没有问题。我收到Maven错误消息:

[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.3.6:build (default-cli) on project 'foo': Could not build image: com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.spotify.docker.client.messages.RegistryAuth: no String-argument constructor/factory method to deserialize from String value ('osxkeychain')

我尝试从.m2/repository删除所有Maven存储库,重新启动docker,并删除所有映像。

稍后我尝试将mvn clean package dockerfile:build运行到两个单独的命令中:

  • mvn package,然后
  • mvn docker:build

mvn package通过,并且mvn docker:build失败,并显示与上述相同的错误。

Maven版本3.5.4, Docker版本18.06.1-ce, build e68fc7a, 操作系统:macOS mojave

我什至试图重新启动我的PC,希望它能解决它...

编辑: 这是Maven Pom插件dockerfile-maven-plugin

...
<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>dockerfile-maven-plugin</artifactId>
    <version>1.3.6</version>
    <configuration>
        <repository>${project.artifactId}</repository>
    </configuration>
</plugin>
...

编辑2:

完整错误消息:

[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.3.6:build (default) on project spring-boot-service: Could not build image: com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.spotify.docker.client.messages.RegistryAuth: no String-argument constructor/factory method to deserialize from String value ('swarm')
[ERROR]  at [Source: N/A; line: -1, column: -1] (through reference chain: java.util.LinkedHashMap["stackOrchestrator"])
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

编辑3:

docker-compose.yml

wrapper:
  image: spring-boot-service:latest
ports:
  - "8080:8080"
expose:
  - "8080"
links:
  - db
  - another-service

已解决:

在我看来,这是dockerfile-maven-plugin的错误版本。我使用了1.3.6,而1.4.7解决了这个问题。

感谢Boris

更新:还有一件事!

确保mvn完成构建的命名正确无误,例如:

[INFO] Successfully built **spring-boot-service:0.0.1-SNAPSHOT**

docker-compose.yml应该看起来像这样:

...
wrapper:
  image: **spring-boot-service:0.0.1-SNAPSHOT**
...

1 个答案:

答案 0 :(得分:2)

这是dockerfile-maven-plugin的配置:

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

注意::使用最新发布的版本1.4.7

这会将插件配置为使用single command构建并推送您的图片:

$ mvn clean deploy

如果只想构建Docker映像,请运行:

$ mvn clean package