【问题标题】:Docker image not getting image name from pom.xmlDocker 映像未从 pom.xml 获取映像名称
【发布时间】:2019-04-28 04:46:19
【问题描述】:

我正在使用 spotify 创建 docker 映像。我的 docker 映像创建成功,但没有名称。我在控制台上低于:

图像将不带名称构建

POM.XML

   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.nv</groupId>
    <artifactId>microeurekaserver</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>MicroEurekaServer</name>
    <description>Eureka Server</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.SR2</spring-cloud.version>
        <docker.image.prefix>nvarshney44/nvarshney</docker.image.prefix>
    </properties>


  <build>
     <plugins>
       <plugin>
         <groupId>com.spotify</groupId>
         <artifactId>docker-maven-plugin</artifactId>
         <version>1.0.0</version>

         <configuration>
            <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
            <forceTags>true</forceTags>
            <imageTags>
                <imageTag>${project.version}</imageTag>
                <imageTag>latest</imageTag>
             </imageTags>
            <resources>
               <resource>
                  <directory>${project.build.directory}</directory>
                  <include>${project.build.finalName}.jar</include>
               </resource>
            </resources>
            <serverId>docker-hub</serverId>
             <registryUrl>https://index.docker.io/v1/</registryUrl>
         </configuration>
      </plugin>

      <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
   </plugins>

</build>

请帮我看看有什么问题。在 Maven 输出中它显示 dockerfile:null 可能是它正在花费一些问题。

【问题讨论】:

  • 我不确定,但 dockerfile 插件在我的情况下要简单一些:&lt;plugin&gt; &lt;groupId&gt;com.spotify&lt;/groupId&gt; &lt;artifactId&gt;dockerfile-maven-plugin&lt;/artifactId&gt; &lt;version&gt;1.4.9&lt;/version&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;build&lt;/id&gt; &lt;phase&gt;package&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;build&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;repository&gt;foo/barrepository&gt; &lt;tag&gt;${project.version}&lt;/tag&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; 除此之外,我建议使用 -X 标志打包以查看更多详细信息

标签: spring-boot docker docker-maven-plugin spotify-docker-client


【解决方案1】:

为了给一个Docker镜像命名,你需要填写“repository”字段:

<configuration>
  <repository>your-name-here</repository> <!-- ${project.artifactId} is a good choice -->
  <tag>${project.version}</tag>
</configuration>

这实际上与 Docker 推送的工作方式一致——它将名称视为存储库地址。

【讨论】:

    【解决方案2】:

    您在哪里定义这些变量值${docker}${project}? 它会是这样的:

    <docker> <image> <prefix> value </prefix> </image> </docker>

    请查看:Using variables in pom.xml

    【讨论】:

    • 我已经编辑了有问题的 pom.xml。请检查...docker.image.prefix 在属性标签中定义...
    • 尝试使用 ${parent.artifactId} 而不是 ${project.artifactId} 请发布您完整的非敏感 pom 值。会有很大帮助
    • 已更改..但它没有使用任何名称..顺便说一句,我需要 project.artifactId 作为名称而不是 parent.artifactId ...两者都有不同的值...
    猜你喜欢
    • 1970-01-01
    • 2021-06-16
    • 2021-12-27
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 2019-11-12
    • 2020-12-20
    • 1970-01-01
    相关资源
    最近更新 更多