由于无法处理“ $ {project.artifactId}”:替换中缺少“:”,因此无法构建Docker映像 [英] Unable to build docker image due to failed to process "${project.artifactId}": missing ':' in substitution

查看:212
本文介绍了由于无法处理“ $ {project.artifactId}”:替换中缺少“:”,因此无法构建Docker映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下命令为Maven项目构建docker映像: mvn clean install -DskipTests -Pdocker

I am trying to build a docker image for a maven project with the command: mvn clean install -DskipTests -Pdocker

我有以下 Dockerfile

FROM openjdk:8-jre

ARG serviceuser=${project.artifactId}

##UPDATES AND INSTALL REQUIRED PACKAGES
RUN apt-get update && \
    apt-get install -y gettext-base sudo && \
    apt-get install -y iptables sudo && \
    adduser --shell /bin/bash ${serviceuser} && \
    adduser ${serviceuser} sudo && \
    echo "%sudo ALL=NOPASSWD: ALL" >> /etc/sudoers

USER ${serviceuser}

##MOVE AND COPY PROJECT FILES INTO CONTAINER
COPY ${project.build.finalName}.jar /home/${serviceuser}/

WORKDIR /home/${serviceuser}

pom.xml 文件包含以下一些内容:(为解释方便起见,将其缩短了)

The pom.xml file has some of the following contents: (Have made it shorter just for explaination)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.book.app</groupId>
  <artifactId>book-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>book-app</name>
  <url>http://maven.apache.org</url>
  <profiles>
    <profile>
      <id>docker</id>
      <build>
        <resources>
          <resource>
            <directory>docker</directory>
            <filtering>true</filtering>
            <targetPath>${project.build.directory}</targetPath>
          </resource>
        </resources>
        <plugins>
          <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>dockerfile-maven-plugin</artifactId>
            <version>1.3.3</version>
            <executions>
              <execution>
                <id>default</id>
                <goals>
                  <goal>build</goal>
                  <goal>push</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <contextDirectory>${project.build.directory}</contextDirectory>
              <repository>test-img:2000/v1/${project.artifactId}</repository>
              <tag>${project.version}</tag>
              <tag>latest</tag>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
  </parent>
  <dependencies>
    ...
  </dependencies>
  <build>
    ...
  </build>
</project>

在我构建时,它会给我以下错误消息...

When i build, it gives me the following error message...

原因:com.spotify.docker.client.exceptions.DockerException:无法处理 $ {project.artifactId}:缺少:代替

Caused by: com.spotify.docker.client.exceptions.DockerException: failed to process "${project.artifactId}": missing ':' in substitution

[错误]无法处理 $ {project.artifactId}:替换中缺少':'

[INFO]内置失败

感谢您提供任何提示或帮助。

I would appreciate any hints or help, thank you.

推荐答案

只要变量名中包含某些非字母数字字符,Docker都会引发此误导性错误。

Docker throws this misleading error whenever you have certain non alpha-numeric characters in your variable name.

我认为正在尝试将其解释为用于指定bash样式的语法默认值替换

I assume that it is trying to interpret them as syntax to specify bash style default value substitution.

为防止此错误,请从变量名中删除字符。

To prevent this error, remove the character from your variable name.

在您的示例中为是导致错误,对我来说是-,我必须替换为 _

In your example it is the . causing the error, for me it was a - which I had to replace with an _.

这篇关于由于无法处理“ $ {project.artifactId}”:替换中缺少“:”,因此无法构建Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆