为什么jar执行的通配符在docker CMD中不起作用?(Why does wildcard for jar execution not work in docker CMD?)

编程入门 行业动态 更新时间:2024-10-26 06:37:19
为什么jar执行的通配符在docker CMD中不起作用?(Why does wildcard for jar execution not work in docker CMD?)

我有一个带有以下CMD的Dockerfile来启动我的春季启动应用程序:

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

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

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

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

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

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

更新根据答案,我能够解决它:

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

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

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...>

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 ;-)

Update Based on the answer I was able to fix it:

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

最满意答案

这种星号扩展是由命令行处理器 - shell完成的,你通过直接调用java来绕过它。

与在Windows下使用“CMD / C”调用命令以获得完全处理的方式大致相同。

改为调用/bin/sh 。

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

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

Invoke /bin/sh instead.

更多推荐

本文发布于:2023-08-07 22:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466154.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通配符   中不   docker   jar   CMD

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!