luthien
luthien

Reputation: 1305

Dockerfile run executable

I'm having a directory that contains a Dockerfile and a JAR file foo.jar.

In the Dockerfile I've written the following:

FROM java:8
EXPOSE 8080
ENTRYPOINT ["java","-jar","foo.jar"]

I build the image with success by running

docker build -t foo-example .

Then I try to run it by running

docker run -ti --rm -p 8080:8080 foo-example

and I'm getting this error:

Error: Unable to access jarfile foo.jar

Any ideas?

Upvotes: 2

Views: 1105

Answers (2)

Taras Velykyy
Taras Velykyy

Reputation: 1801

You should use docker COPY or ADD command. COPY is more preferred as described here: https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#add-or-copy

FROM java:8
EXPOSE 8080
COPY foo.jar ~/.
ENTRYPOINT ["java","-jar","foo.jar"]

Upvotes: 4

Artem Barger
Artem Barger

Reputation: 41232

You need to make foo.jar available inside the container, e.g. copy it inside and make sure to specify exact location while executing it. Read docker docs about ADD command.

Basically you need to add something along these lines:

ADD foo.jar foo.jar

Using COPY is another alternative:

COPY foo.jar ~/.

Upvotes: 3

Related Questions