为什么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.

为什么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.