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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 03:25:42  来源:igfitidea点击:

pass parameters to docker entrypoint

javadockerdockerfile

提问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.shin entrypoint? ( as -Dversion=$versionor others )

我如何./run.sh在没有入口点的情况下为 java 做动态参数?(作为-Dversion=$version或其他人)

I want pass this parameters when start container.

我想在启动容器时传递这个参数。

--entrypoint somethingdoesn'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 CMDinstruction, 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 mycontainerthe

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(覆盖默认情况)