Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker not able to run Java app

Tags:

java

docker

I have the following project directory structure:

myapp/
    grails-app/ (its a grails app, derrrr)
    target/
        myapp.jar (built by grails)
    myapp.yml

...where target/myapp.jar is the executable JAR (actually a self-contained web app running embedded Jetty), and where myapp.yml is a config file required at startup.

Here is my Dockerfile:

FROM java:8
MAINTAINER My Name <[email protected]>

WORKDIR /

ADD ./target/myapp.jar /myapp.jar
ADD ./myapp.yml /myapp.yml

EXPOSE 8080

CMD ["java", "-jar myapp.jar myapp.yml"]

I then build the image with docker build -t myapp .. It builds successfully I then try to run the image via docker run myapp and get:

Unrecognized option: -jar myapp.jar myapp.yml
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Any idea what could be going wrong here, and what I need to do to fix this or troubleshoot it?

like image 219
smeeb Avatar asked Oct 05 '15 19:10

smeeb


People also ask

Does Docker need JDK?

When creating a Docker image, we should only assign the necessary resources to function correctly. This means that we should start by using an appropriate Java Runtime Environment (JRE) for your production image and not the complete Java Development Kit (JDK).

Can Docker run GUI apps?

Follow the below steps to run a GUI application inside Docker: Step 1: Install and Start Docker and check the status and restart the service. The Systemctl commands are used to manage system services. systemctl start docker // to start the docker service.


1 Answers

You're giving all your parameters as one single parameter, but they are distinct. You should do

CMD ["java", "-jar", "myapp.jar", "myapp.yml"]
like image 77
eis Avatar answered Oct 16 '22 23:10

eis