How to resolve 'missing : in substitution' when building docker image
1. The purpose of this post
Sometimes, when you build a Docker image, you might encounter the following error:
Step 6/9 : COPY ${JAR_FILE} ${root.dir}/app.jarfailed to process "${root.dir}/app.jar": missing ':' in substitution
2. Environments
- Docker 18.09
3. The Dockerfile
Here is the Dockerfile that causes the problem:
FROM openjdk:8-jdk-alpineMAINTAINER bswen.comLABEL appName="myserver"ARG JAR_FILE=target/*-exec.jarENV root.dir="/opt/myserver"COPY ${JAR_FILE} ${root.dir}/app.jar # this line failedWORKDIR ${root.dir}ENTRYPOINT ["java","-jar","app.jar"]EXPOSE 8080
4. The solution
The issue arises because Docker does not support the use of .
in environment variable names. To resolve this, replace .
with _
in the Dockerfile, as shown below:
FROM openjdk:8-jdk-alpineMAINTAINER bswen.comLABEL appName="myserver"ARG JAR_FILE=target/*-exec.jarENV rootdir="/opt/myserver" # change root.dir to rootdirCOPY ${JAR_FILE} ${rootdir}/app.jar # change root.dir to rootdirWORKDIR ${rootdir}ENTRYPOINT ["java","-jar","app.jar"]EXPOSE 8080
After making this change, rebuild the Docker image, and the error should no longer occur.
5. Summary
In this post, we explored how to resolve the “missing : in substitution” error when building a Docker image. The key takeaway is to avoid using .
in environment variable names within the Dockerfile. Instead, replace .
with _
to ensure compatibility with Docker’s syntax rules. By following this simple adjustment, you can successfully build your Docker image without encountering this error.
Final Words + More Resources
My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!