6

I currently have a docker container with an Ubuntu(17.10) image installed with other packages included. However, I'm currently having difficulty trying to install Java onto this container in addition to the current image.

Current Dockerfile :

FROM cityofzion/neo-privatenet
ADD files/ files/
ENTRYPOINT [ "/bin/bash" ]

When trying to find information on how to do this and testing inside of the container most suggest using this command: apt-get install -y oracle-java9-installer

However this results in:E: Unable to locate package oracle-java9-installer

I have also tried this suggested command wget http://download.java.net/java/GA/jdk9/9/binaries/jdk-9+181_linux-x64_bin.tar.gz

Which produces this result HTTP request sent, awaiting response... 404 Not Found - ERROR 404: Not Found.

I have only tried running these commands in the container, since that is how they would be run and they seem to be failing.

Can anyone suggest what I can include into my Dockerfile that install java onto my image?

Thanks in advance.

user1522263
  • 103
  • 1
  • 1
  • 8
  • Possible duplicate of [Installing java in Docker image](https://stackoverflow.com/questions/31196567/installing-java-in-docker-image) – hnefatl Apr 10 '18 at 00:14
  • 1
    There are already a heap of existing Ubuntu+Java containers you can use as a base. For example ~ https://github.com/cogniteev/docker-oracle-java/tree/master/oracle-java9 – Phil Apr 10 '18 at 00:14

3 Answers3

7

You can also directly pull any of the open-jdk images mentioned at (https://hub.docker.com/_/openjdk/) and use it. There is no need to install Ubuntu in docker image and then install Java on top of it. These images already use Ubuntu (with bare-minimum file system).

Harsh Mehta
  • 571
  • 3
  • 16
  • Thanks for the link, clarifies things immensely. One thing that still isn't clear, what should a person use on production/development networks and local PC? I was hoping to use ubuntu 18 on prod mainly because I know it very well and trust it. That's way I was working to stand up ubuntu with java not a prebuild docker image, keep local and prod as close as possible. Is this wrong? – gunslingor Jul 06 '20 at 19:40
3

add to to your docker file

RUN \
  apt-get update && \
  apt-get install -y software-properties-common && \
  echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
  add-apt-repository -y ppa:webupd8team/java && \
  apt-get update && \
  apt-get install -y oracle-java9-installer && \
  rm -rf /var/lib/apt/lists/* && \
  rm -rf /var/cache/oracle-jdk8-installer

  ENV JAVA_HOME /usr/lib/jvm/java-9-oracle
  • 1
    `E: Package 'oracle-java9-installer' has no installation candidate ERROR: Service 'app' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y software-properties-common && echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && add-apt-repository -y ppa:webupd8team/java && apt-get update && apt-get install -y oracle-java9-installer && rm -rf /var/lib/apt/lists/* && rm -rf /var/cache/oracle-jdk8-installer' returned a non-zero code: 100` – Peter Weyand Sep 10 '18 at 20:16
0

Following from here

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
  • Oracle JDK version 7

    sudo apt-get install oracle-java7-installer

  • Oracle JDK version 8

    sudo apt-get install oracle-java8-installer

Sukma Wardana
  • 540
  • 8
  • 21
  • Tried this solution like this : `FROM cityofzion/neo-privatenet RUN apt-get install python-software-properties RUN add-apt-repository ppa:webupd8team/java RUN apt-get update RUN apt-get install oracle-java8-installer ADD files/ files/ ENTRYPOINT [ "/bin/bash" ]` Which resulted in `E: Unable to locate package python-software-properties` Thank you for your reply though. – user1522263 Apr 10 '18 at 02:06
  • 1
    Will not work from April 2019 onwards due to Oracle Licence change – JARC Aug 20 '19 at 10:17