maven - 构建 Spring Boot 应用程序的 Docker 镜像文件
问题描述
我正在尝试使用 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 的新手。
解决方案
这似乎是一个错误,默认情况下插件将 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>
推荐阅读
- android - 移动设备上最高效的 Websocket Ping 间隔
- sql - 从月份计算日期
- visual-studio-code - 单击 Visual Studio Code 标题栏中的应用程序关闭按钮时,如何禁用、删除或强制提示?
- class - 如何从课堂上获取细节
- homebrew - 酿造安装nvm。nvm:找不到命令
- python - plt.bar - x 轴绘图不符合 x 轴标签(python 中的 matplotlib)
- python - Pandas ValueError:索引数据帧时,系列的真值不明确
- python - 使用查找数据框替换数据框中的值
- c - 位操作良好实践
- mysql - 优化 Yii2 MYSQL 查询