I'm not entirely sure if this is what you would want to accomplish, but...
Dockerfile exposes both ENTRYPOINT
and CMD
for being able to execute commands. These also can be used in conjunction, but in this case the ENTRYPOINT
will be the command what we want to execute and the CMD
will represent some default arguments for the ENTRYPOINT
(docs).
For example:
FROM openjdk:11
COPY . /target/app.jar
ENTRYPOINT ["java", "-jar", "app.jar", "--argumentA=valA"]
CMD ["--argumentB=valB"]
The --argumentB=valB
will be appended to the java -jar app.jar --argumentA=valA
, if we run the image like this:
docker build -t app .
docker run app # # the command executed will be java -jar app.jar --argumentA=valA --argumentB=valB
But the CMD
part will be overridden if we provide other arguments when we run the docker image:
docker build -t app .
docker run app --argumentA=valC # the command executed will be java -jar app.jar --argumentA=valA --argumentB=valC
Also, we can commit the CMD
and have the ENTRYPOINT
only, if we don't require some defaults to be appended to the ENTRYPOINT
.