Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does wildcard for jar execution not work in docker CMD?

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"]
like image 717
adebasi Avatar asked Jan 02 '17 13:01

adebasi


People also ask

How can I override CMD when running a docker image?

As the operator (the person running a container from the image), you can override that CMD just by specifying a new COMMAND. If the image also specifies an ENTRYPOINT then the CMD or COMMAND get appended as arguments to the ENTRYPOINT. So to do what you want you need only specify a cmd, and override using /bin/bash .

How does CMD work in Dockerfile?

The CMD command​ specifies the instruction that is to be executed when a Docker container starts. This CMD command is not really necessary for the container to work, as the echo command can be called in a RUN statement as well. The main purpose of the CMD command is to launch the software required in a container.

Can we override CMD in Dockerfile?

Docker CMD The CMD instruction is only utilized if there is no argument added to the run command when starting a container. Therefore, if you add an argument to the command, you override the CMD. To show you how CMD works, we will create a sample container with CMD instruction.

Can both run and CMD instruction be used interchangeably in the Dockerfile explain?

Commands such as CMD, RUN and ENTRYPOINT are interchangeably used when you are writing a dockerfile to create the Docker Image.


1 Answers

CMD java -jar /app/file*.jar worked for me

like image 65
Sam Avatar answered Oct 19 '22 20:10

Sam