java 将参数传递给 docker 入口点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38468916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pass parameters to docker entrypoint
提问by kvendingoldo
I have Dockerfile
我有 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 )
我如何./run.sh
在没有入口点的情况下为 java 做动态参数?(作为-Dversion=$version
或其他人)
I want pass this parameters when start container.
我想在启动容器时传递这个参数。
--entrypoint something
doesn't work on Docker 1.11 ;(
--entrypoint something
不适用于 Docker 1.11 ;(
回答by Jiri Kremser
You can append your dynamic parameters at the end of the docker run ...
. You haven't specified any CMD
instruction, so it'll work.
您可以将动态参数附加到docker run ...
. 你还没有指定任何CMD
指令,所以它会起作用。
What is actually run without specifying any command at the end, when running the docker run ...
, is this:
实际运行时没有在最后指定任何命令,在运行时docker run ...
,是这样的:
ENTRYPOINT CMD
(it's concatenated and there is a space in between)
ENTRYPOINT CMD
(它是串联的,中间有一个空格)
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
docker run mycontainer
这
java -jar my_app.jar --spring.config.location=classpath:/srv/app/configs/application.properties
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
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)
它将使用不同的属性文件和系统属性运行version
(覆盖默认情况)