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?
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).
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.
You're giving all your parameters as one single parameter, but they are distinct. You should do
CMD ["java", "-jar", "myapp.jar", "myapp.yml"]
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