Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install java successfully using the dockerfile however its says java command not found

Tags:

docker

Here is my docker file

RUN apt-get install -y --no-install-recommends software-properties-common
RUN add-apt-repository -y ppa:openjdk-r/ppa
RUN apt-get update
RUN apt-get install -y openjdk-8-jdk
RUN apt-get install -y openjdk-8-jre
RUN update-alternatives --config java
RUN update-alternatives --config javac

when I log into the container using sudo docker run -t -i dockerfile and type java or javac it works. I can see it has been installed successfully however when i run it with the file below it says "java command not found"?

RUN apt-get install -y --no-install-recommends software-properties-common
RUN add-apt-repository -y ppa:openjdk-r/ppa
RUN apt-get update
RUN apt-get install -y openjdk-8-jdk
RUN apt-get install -y openjdk-8-jre
RUN update-alternatives --config java
RUN update-alternatives --config javac
ENTRYPOINT ["java" "-jar", "/home/project/hello.jar"]
CMD [""]

sudo docker run -t -i dockerfile java command not found ?

like image 231
user1870400 Avatar asked Apr 13 '16 20:04

user1870400


People also ask

How do I install something in Dockerfile?

To install packages in a docker container, the packages should be defined in the Dockerfile. If you want to install packages in the Container, use the RUN statement followed by exact download command . You can update the Dockerfile with latest list of packages at anytime and build again to create new image out of it.

Do you need CMD in Dockerfile?

Both ENTRYPOINT and CMD are essential for building and running Dockerfiles—it simply depends on your use case. As a general rule of thumb: Opt for ENTRYPOINT instructions when building an executable Docker image using commands that always need to be executed.

Does Docker support Java 11?

Controllers use Java 11 by default If you are running one of the Jenkins Docker controller images that does not include a JDK version in its label, the Java runtime will switch from Java 8 to Java 11 with the upgrade. For example: Jenkins 2.306 running as jenkins/jenkins:latest uses Java 8.


2 Answers

ENTRYPOINT ["java" "-jar", "/home/project/hello.jar"]

You forgot a comma before "-jar".

like image 196
kliew Avatar answered Oct 21 '22 04:10

kliew


you're probably missing the JAVA_HOME and PATH declaration.

ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 #This can vary
ENV PATH $PATH:$JAVA_HOME/bin

And build the docker image with --no-cache option
like image 37
MrE Avatar answered Oct 21 '22 03:10

MrE