Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass parameters to docker entrypoint

I have Dockerfile

FROM    java:8
ADD     my_app.jar /srv/app/my_app.jar
WORKDIR /srv/app
ENTRYPOINT ["java", "-jar", "my_app.jar", "--spring.config.location=classpath:/srv/app/configs/application.properties"]

How I can do dynamic paramethers for java without ./run.sh in entrypoint? ( as -Dversion=$version or others )

I want pass this parameters when start container.

--entrypoint something doesn't work on Docker 1.11 ;(

like image 733
kvendingoldo Avatar asked Jul 19 '16 21:07

kvendingoldo


1 Answers

You can append your dynamic parameters at the end of the docker run .... You haven't specified any CMD instruction, so it'll work.

What is actually run without specifying any command at the end, when running the docker run ..., is this:

ENTRYPOINT CMD (it's concatenated and there is a space in between)

So you can also use something like

...
ENTRYPOINT ["java", "-jar", "my_app.jar"]
CMD ["--spring.config.location=classpath:/srv/app/configs/application.properties"]

which means, when using

docker run mycontainer the

java -jar my_app.jar --spring.config.location=classpath:/srv/app/configs/application.properties

will be invoked (the default case), but when running

docker run mycontainer --spring.config.location=classpath:/srv/app/configs/some_other_application.properties -Dversion=$version

it'll be run w/ different property file and with the system property called version (overriding the default case)

like image 129
Jiri Kremser Avatar answered Oct 20 '22 05:10

Jiri Kremser