svenhornberg
svenhornberg

Reputation: 15766

Java in python3-onbuild docker

I need to run a java programm inside the python3-onbuild image (it is based on debian jessie) . I extended the dockerfile with the installation of java, but if i try to print out the version it results in

System error: exec: "java": executable file not found in $PATH

I created a repository with my code.

My Dockerfile:

FROM python:3-onbuild
ONBUILD RUN ["apt-get", "install", "-y", "openjdk-7-jre"]

# Define commonly used JAVA_HOME variable
ONBUILD ENV JAVA_HOME /usr/java/default
ONBUILD ENV PATH $PATH:$JAVA_HOME/bin

CMD ["java", "-version"]

Any idea whats wrong and how I can fix it ?

Upvotes: 0

Views: 1259

Answers (1)

Adrian Mouat
Adrian Mouat

Reputation: 46500

I think you are misunderstanding ONBUILD. From the docs:

The ONBUILD instruction adds to the image a trigger instruction to be executed at a later time, when the image is used as the base for another build. The trigger will be executed in the context of the downstream build, as if it had been inserted immediately after the FROM instruction in the downstream Dockerfile.

So, when docker build encounters the FROM instruction in your Dockerfile, it will execute on ONBUILD instructions from the python image. In your Dockerfile, the ONBUILD instructions are never executed, as they would only be triggered if the image is referenced from another Dockerfile.

I think you just meant to use RUN instead of ONBUILD, but I'm not sure why you are trying to use ONBUILD at all.

Upvotes: 2

Related Questions