7

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 ?

user1870400
  • 6,028
  • 13
  • 54
  • 115
  • There's a big chance the `PATH` is different than you expected. Try using fully qualified pathname to java. – alvits Apr 13 '16 at 20:23
  • I can see it is installed in /usr/bin/java under containers volume however when I use absolute path it still doesn't work. Although I would like to find a way to not use absolute path – user1870400 Apr 13 '16 at 21:25
  • 2
    Suggestion: Try using an official Java image instead: https://hub.docker.com/_/java – Mano Marks Apr 14 '16 at 00:54
  • @ManoMarks We had this discussion here: http://stackoverflow.com/questions/36587850/best-way-to-install-java-8-using-docker yet for some unknown reason his container turns out misconfigured. The java image is the best approach IMO – buddy123 Apr 14 '16 at 05:43

2 Answers2

14

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

You forgot a comma before "-jar".

kliew
  • 3,073
  • 1
  • 14
  • 25
5

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
user1870400
  • 6,028
  • 13
  • 54
  • 115
MrE
  • 19,584
  • 12
  • 87
  • 105
  • still doesn't work. I have set it to the following and I verified these exists at the location specified below ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 ENV PATH $PATH:$JAVA_HOME/bin – user1870400 Apr 16 '16 at 18:03
  • can you find java in the container? maybe the path is not what you think it is. – MrE Apr 16 '16 at 19:08
  • as I stated in my earlier comment I was able to verify the location of where Java was installed in the container and it looks right – user1870400 Apr 16 '16 at 21:39
  • I've actually just seen a similar issue with an alpine docker image, where java was put in `/opt/jdk/`. It would not find java, and I had to make the java path be `/usr/java/default/` for the image to work. It may be that the program hard codes the java path to be that instead of using the PATH. I don't know, but that fixed it for me. – MrE Apr 17 '16 at 01:54
  • I am not using any Java image. I just use apt-get as listed above after failing to install with java:8 image. I have also installed say mysql and I have the same issue which is I cannot specify mysql -h localhost -u abcd -pabcd in the docker file it says mysql command not found but when I log in to the image and do mysql it works so I am not sure whats happening – user1870400 Apr 17 '16 at 04:56
  • you might be having a problem with cache. try rebuilding your image with `-no-cache` and see if it helps. – MrE Apr 17 '16 at 05:01
  • Actually I am still facing the same problem with --no-cache – user1870400 Apr 17 '16 at 23:10
  • I'm facing a similar situation. I have installed java from gz file [cd /work && tar zxvf jre-8u141-linux-x64.tar.gz] and set the path using RUN PATH "/work/jre1.8.0_141/bin". But it does not work [starting container process caused "exec: \"java\": executable file not found in $PATH" I even tried to use CMD /work/jre1.8.0_141/bin/java , this too does not work. – Prakash Jan 10 '18 at 13:00