本文介绍了为什么执行jar的通配符在docker CMD中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Dockerfile 和以下 CMD 来启动我的spring boot应用程序:

I have a Dockerfile with the following CMD to start my spring boot app:

FROM java:8-jre
# ...
CMD ["java", "-jar", "/app/file*.jar"]

当我尝试从创建的图像启动容器时,我得到:

When I try to start a container from the created image I get:

Error: Unable to access jarfile /app/file*.jar

但是当我在启动容器时覆盖 CMD 并在容器中执行命令时,一切正常:

But when I override the CMD while starting the container and execute the command in the container everything works fine:

docker run -it <imageId> bash
root@<containerId>:/app# java -jar /app/file*.jar
<spring boot app starts...>

是否可以通过docker CMD在 java -jar 命令中使用通配符?请不要告诉我不要使用通配符.我想使用它是有原因的;-)

Is it possible to use wildcards with java -jar command using docker CMDs? Please don't tell me not to use wildcards. I want to use it cause of reasons ;-)

更新根据答案,我得以解决:

UpdateBased on the answer I was able to fix it:

CMD ["/bin/sh", "-c", "java -jar /app/file*.jar"]

推荐答案

这种星号扩展是由命令行处理器(shell)完成的,您可以通过直接调用Java来规避这一问题.

This kind of asterisk expansion is done by the command line processor - the shell - and you circumvent that by invoking java directly.

与在Windows下使用"CMD/C"调用命令的方式几乎相同,以获得完整的处理.

Much the same way as commands should be invoked with "CMD /C" under Windows to get full treatment.

改为调用/bin/sh .

这篇关于为什么执行jar的通配符在docker CMD中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 09:18