E
E
Egor Irvin2022-02-06 11:17:20
Docker
Egor Irvin, 2022-02-06 11:17:20

How to run jar file in docker container?

Dockerfile

FROM java:8 #Try
the same with FROM ubuntu
#RUN apt install -y openjdk-8-jdk
RUN mkdir -p /vagrant/Docker/app
WORKDIR /vagrant/Docker/app
COPY . /vagrant/Docker/app

#
EXPOSE 9000
ENV TZ Europe/Yekaterinburg
CMD ["-jar", "/vagrant/Docker/app/app.jar"]

Error with java image:
docker: Error response from daemon: OCI runtime create failed : container_linux.go:380: starting container process caused: exec: "-jar": executable file not found in $PATH: unknown.
Error with ubuntu image:
Error: Unable to access jarfile app.jar

Through the Linux command line, the file launch looks like java -jar app.jar. And what to use CMD or ENTRYPOINR for this? And what will the structure look like?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2022-02-06
@AsphaltHero_0

WORKDIRRUN mkdir -p ...- creates a directory by itself, it is not necessary to call it separately .
EXPOSE 9000you can not specify - it does nothing.

Through the Linux command line, the file launch looks like java -jar app.jar

And in the Dockerfile this command will be the same:
ENTRYPOINT ["java", "-jar", "/vagrant/Docker/app/app.jar"]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question