A.Dumas
A.Dumas

Reputation: 3267

How to start a fat jar in docker?

I want to start my fat JAR inside a Docker container

Docker file

FROM java:8-jre
COPY config.yml /opt/hello/
COPY build/libs/Dockerwizard.jar /opt/hello/
EXPOSE 80
WORKDIR /opt/hello
CMD ["java", "-Xms128m", "-Xmx1500m", "-Dfile.encoding=UTF-8", "-jar", "Dockerwizard.jar", "server", "config.yml"]

Everytime I run

docker build --tag=myapp .

and

docker run -p 18080:8080 -t -i myapp

I get the message

Error: Unable to access jarfile Dockerwizard.jar

How can I resolve this?

Upvotes: 1

Views: 2101

Answers (2)

kakabali
kakabali

Reputation: 4033

Try changing the WORKDIR in your Dockerfile

WORKDIR /opt/chat is incorrect

It should be /opt/hello

Update

you have updated the question and renamed /chat to /hello everywhere - so you have made a correction to your error/ mistake

Upvotes: 1

GhostCat
GhostCat

Reputation: 140457

It says:

COPY build/libs/Dockerwizard.jar /opt/hello/
...WORKDIR /opt/chat

So you are putting the Jar into /opt/hello, but then you want to run it from /opt/chat.

Maybe you want to look into using consistent path information. Beyond that, when you are not using the -cp option of java, you always have the issue that your CLASSPATH might be incomplete. So try adding -cp . for example.

Upvotes: 2

Related Questions