【问题标题】:Build Docker Image File of Spring Boot Application构建 Spring Boot 应用程序的 Docker 镜像文件
【发布时间】:2019-07-13 02:58:36
【问题描述】:

我正在尝试使用 dockerfile-maven-plugin 为我的 spring boot maven 项目构建一个 docker 映像。我在 Windows 7 上使用 Docker Tool Box,它运行良好。

我得到以下错误:

未能加载 Google 应用程序默认凭据 java.io.IOException:应用程序默认凭据不是 可用的。如果在 Google Compute Engine 中运行,它们就可用。 否则,环境变量 GOOGLE_APPLICATION_CREDENTIALS 必须定义指向定义凭据的文件。看 https://developers.google.com/accounts/docs/application-default-credentials 了解更多信息。

Pom.XML 构建

<build>
    <plugins>
        <plugin>
          <groupId>com.spotify</groupId>
          <artifactId>dockerfile-maven-plugin</artifactId>
          <version>1.4.10</version>
          <executions>
            <execution>
              <id>default</id>
              <goals>
                <goal>build</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
             <serverId>docker-hub</serverId>
            <repository>${project.artifactId}</repository>
            <tag>${project.version}</tag>
            <buildArgs>
              <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
            </buildArgs>
          </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                  <goals>
                    <goal>repackage</goal>
                  </goals>
                </execution>
          </executions>
             <configuration>
                <outputDirectory>D:\spring\MicroServiceOutput</outputDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

我无法理解为什么我们需要谷歌默认凭据来构建本地映像。请帮助我,因为我是 Docker World 的新手。

【问题讨论】:

  • 这个answer 可能会有所帮助
  • 它没有创建 Docker 文件...
  • 我已经用一些细节更新了答案,mvn clean install fabric8:build
  • 获取'不能包含项目工件:'错误..

标签: maven spring-boot docker docker-toolbox dockerfile-maven-plugin


【解决方案1】:

好像是bug,默认情况下插件将googleContainerRegistryEnabled标志设置为true,所以你必须将该标志更改为false,试试这个:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.RC2</spring-cloud.version>
    <docker.image.prefix>prefix</docker.image.prefix>
    <docker.image.name>${project.artifactId}</docker.image.name>
    <docker.image.tag>${project.version}</docker.image.tag>
    <docker.file>Dockerfile</docker.file>
</properties>
        ...
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>dockerfile-maven-plugin</artifactId>
            <version>1.4.10</version>
            <configuration>
                <googleContainerRegistryEnabled>false</googleContainerRegistryEnabled>
                <repository>${docker.image.prefix}/${docker.image.name}</repository>
                <tag>${docker.image.tag}</tag>
                <dockerfile>${docker.file}</dockerfile>
            </configuration>
            <executions>
                <execution>
                    <id>build</id>
                    <goals>
                        <goal>build</goal>
                        <goal>tag</goal>
                    </goals>
                </execution>
                <execution>
                    <id>push</id>
                    <goals>
                        <goal>push</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

【讨论】:

    猜你喜欢
    • 2020-03-12
    • 2021-06-05
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 2021-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多