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
?
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.
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.
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.
ENTRYPOINT ["java" "-jar", "/home/project/hello.jar"]
You forgot a comma before "-jar"
.
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
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