others-How to solve 'missing : in substitution' when build docker image

1. The purpose of this post

Sometimes, when you build a docker images file, you would get this error:

Step 6/9 : COPY ${JAR_FILE} ${root.dir}/app.jar
failed to process "${root.dir}/app.jar": missing ':' in substitution

2. Environments

  • docker 18.09

3. The Dockerfile

Let’s see the Dockerfile that causes the problem:

FROM openjdk:8-jdk-alpine
MAINTAINER bswen.com
LABEL appName="myserver"
ARG JAR_FILE=target/*-exec.jar
ENV root.dir="/opt/myserver"
COPY ${JAR_FILE} ${root.dir}/app.jar # this line failed
WORKDIR ${root.dir}
ENTRYPOINT ["java","-jar","app.jar"]
EXPOSE 8080

4. The solution

You should not use ‘.’ in the Dockerfile, replace it with ‘_’, like this:

FROM openjdk:8-jdk-alpine
MAINTAINER bswen.com
LABEL appName="myserver"
ARG JAR_FILE=target/*-exec.jar
ENV rootdir="/opt/myserver" # change root.dir to rootdir
COPY ${JAR_FILE} ${rootdir}/app.jar # change root.dir to rootdir
WORKDIR ${rootdir}
ENTRYPOINT ["java","-jar","app.jar"]
EXPOSE 8080

Now rebuild the docker image, everything works fine.