I'm trying to run a docker container that uses maven to deploy a java application Without using docker, the command that I use to deploy is "java -jar app-v0.1.jar"
Since the version of my application tends to change, (app-v0.1, v0.2 ...) what I usually do is running "java -jar *.jar" (There's always only 1 .jar file in the working folder). This works locally.
However, this seems to be unable to apply when building a Docker container. Here's my dockerfile
FROM openjdk:8
WORKDIR /app
COPY *.jar .
CMD ["java", "-jar", "*.jar"]
EXPOSE 8181
I can build the docker image from that Dockerfile. But when I try to run the container, I always get the Error: Unable to access jarfile *.jar.
I also tried:
COPY target/*.jar .
RUN file=`find . -name "*.jar" -exec basename {} \;`
CMD ["java", "-jar", "${file}"]
which returns Error: Unable to access jarfile ${file}
If I change the "*.jar" to a specific name, for example
CMD ["java", "-jar", "app-v0.1.jar"]
everything works normally. But clearly I don't want to change my Dockerfile every time there's a code update in my app.
Is there a way in which I can put variables in the Dockerfile, something like "
CMD ["java", "-jar", "${filename}.jar"] "?
(If this helps: I'm using Jenkins pipeline to automate the docker building process)