Build Docker Image File of Spring Boot Application

1.9k Views Asked by At

I am trying to build a docker image for my spring boot maven project by using dockerfile-maven-plugin. I am using Docker Tool Box on windows 7 and it is running fine.

I am getting Below Error:

Failed to load Google application default credentials java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.

Pom.XML Build

<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>

I am not able to get that why we need google default credential to build a local image.Please help me out as I am new to Docker World.

1

There are 1 best solutions below

0
On

It seems that's a bug, by default the plugin set googleContainerRegistryEnabled flag to true, so you have to change that flag to false, try this:

<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>