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"]
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 .
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.
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.
Commands such as CMD, RUN and ENTRYPOINT are interchangeably used when you are writing a dockerfile to create the Docker Image.
CMD java -jar /app/file*.jar
worked for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With