docker run pass arguments to entrypoint
You should unleash the power of combination of ENTRYPOINT
and CMD
.
Put the beginning part of your command line, which is not expected to change, into ENTRYPOINT
and the tail, which should be configurable, into CMD
. Then you can simple append necessary arguments to your docker run
command.
Like this:
Dockerfile
FROM openjdk
ADD . /dir
WORKDIR /dir
COPY ./test-1.0.1.jar /dir/test-1.0.1.jar
ENTRYPOINT ["java", "-jar"]
CMD ["/dir/test-1.0.1.jar"]
Sh
# this will run default jar - /dir/test-1.0.1.jar
docker run testjava
# this will run overriden jar
docker run testjava /dir/blahblah.jar
This article gives a good explanation: https://medium.freecodecamp.org/docker-entrypoint-cmd-dockerfile-best-practices-abc591c30e21
Use ENTRYPOINT
in its exec form
ENTRYPOINT ["java", "-jar", "/dir/test-1.0.1.jar"]
then when you run docker run -it testjava $value
, $value
will be "appended" after your entrypoint, just like java -jar /dir/test-1.0.1.jar $value