Docker Community Forums

Share and learn in the Docker community.

Create docker image for java application using jar file


(Maryem) #1

Hey there, I’m getting started with docker.
I’m trying to run a java application using dockerfile.
Here’s my dockerfile :

FROM java:7
MAINTAINER Maryem […]
COPY . /my/path/to/the/java_application
WORKDIR /my/path/to/the/java_application
CMD [“java”, “cmd_to_run”, “-jar”, “/my/path/to/the/java_application/file.jar”, “other_cmd_to_run_my_jar”]

it builds successfully, but when I try to run using the command docker run -i -t maryem/my_app docker cannot locate some files that the jar file is using. I specified the path to these files in conf.txt that i putted in my application folder.

I don’t know if there is another way to tell docker how to call files in conf.txt

I’m stuck in this problem.

any help is much appreciated.


(Midalias) #2

did you find a solution for this?
I’m looking for a way to execute java -jar app.jar server config.yml I have tried variations of CMD but the java command is not executed


(Sam) #3

cmd requires each piece to be in double quotes, separated by commas… (json string array)


(Midalias) #4

Thanks for replying. Yes, I had it like that. But when I was executing docker run using that image I was expecting a java process executed inside of the container (I was looking using ps aux | grep java) and there was no java process running. Anyway it is running in the host.


(Sam) #5

No way I’ve never seen a cmd run or entry point running the host


(Sam) #6

And the Java process must stay running or else the container will terminate