Unable to use variables on the CMD line:
#CMD ["/opt/jdk/bin/java", "-jar", "${ARTIFACTID}-${VERSION}.${PACKAGING}"]
CMD ["/opt/jdk/bin/java", "-jar", "ssltools-domain-LATEST.jar"]
Latest line works, not the first.
Any help or workaround very appreciated
When you write the arguments to CMD
(or ENTRYPOINT
) as a JSON string, as in...
CMD ["/opt/jdk/bin/java", "-jar", "ssltools-domain-LATEST.jar"]
...the command is executed directly with the exec
system call and is not processed by a shell. That means no i/o redirection, no wildcard processing...and no variable expansion. You can fix this in a number of ways:
You can just write it as a plain string instead, as in:
CMD /opt/jdk/bin/java -jar ${ARTIFACTID}-${VERSION}.${PACKAGING}
When the argument is not a JSON construct, it gets passed to sh -c
.
You can do as suggested by Philip, and pass the arguments to sh -c
yourself:
CMD ["sh", "-c", "/opt/jdk/bin/java -jar ${ARTIFACTID}-${VERSION}.${PACKAGING}"]
Those two options are basically equivalent.
A third option is to put everything into a shell script, and then run that:
COPY start.sh /start.sh
CMD ["sh", "/start.sh"]
This is especially useful if you need to perform more than a simple command line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With