How to install / add jdk 7 to Docker Container

I created a docker image with Python as base on my Ubuntu 14.04 machine. The docker version I'm using is 1.12.3. The base Python OS used in the image is Debian. I also require JAVA 7 (JDK 7) in my docker image. It has several Python scripts as well as several scripts that also require the JDK.

I managed to get JDK 7 in my image, but it has stopped working over the past few days. This is throwing an error that the oracle-jdk-7 package is no longer available. Then I tried to get the contents of the Dockerfile JDK 7 Dockerfile and added these lines to my dockerfile. It worked a couple of times and then started throwing the error that the space is not enough.

But space is not an issue since "/ var" is only 29% occupied. Below is my content Dockerfile.

FROM python:2.7

ENV http_proxy http://http.proxy.abc.com:8000
ENV https_proxy http://http.proxy.abc.com:8000

RUN \
  apt-get update && \
  apt-get install -y openjdk-7-jdk && \
  rm -rf /var/lib/apt/lists/*

ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64

RUN pip install datetime && \
pip install pandas && \
pip install xlrd && \
pip install email && \
pip install Jinja2 && \
pip install bokeh==0.12.4

      

And I've also tried following jdk 7:

RUN    echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee /etc/apt/sources.list.d/webupd8team-java.list && \
       echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list && \
       apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 && \
       apt-get update -qq && \
       echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \
       apt-get install oracle-java7-installer libxext-dev libxrender-dev libxtst-dev -y --no-install-recommends && \
       apt-get clean autoclean && \
       apt-get autoremove --yes && \
       rm -rf /var/lib/{apt,dpkg,cache,log}/ && \
      rm -rf /var/cache/oracle-jdk7-installer

      

This throws an error that loads with a 404 error and Oracle JDK 7 won't load. This worked fine until a few days ago.

I tried this too.

RUN \
  apt-get update && \
  apt-get install -y openjdk-7-jdk && \
  rm -rf /var/lib/apt/lists/*

      

This generates an error that the space is full. I can see that "/ var" is only 29% busy.

Tried this too.

RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y  software-properties-common && \
    add-apt-repository ppa:webupd8team/java -y && \
    apt-get update && \
    echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \
    apt-get install -y oracle-java8-installer && \
    apt-get clean

      

This raises an error that multiple packets are skipping.

Please help me get jdk 7 in my docker image. Any JDK type. Oracle JDK or open jdk.

Thanks in advance.

+3


source to share


3 answers


Your environment contains a proxy definition

ENV http_proxy http://http.proxy.abc.com:8000
ENV https_proxy http://http.proxy.abc.com:8000

      

with this, all traffic to the outside is directed to a non-existent location. Remove these lines and docker can fetch the apt resources.

So in addition, I'll give you the complete docker file:

FROM python:2.7-wheezy

RUN pip install datetime && \
pip install pandas && \
pip install xlrd && \
pip install email && \
pip install Jinja2 && \
pip install bokeh==0.12.4


# add webupd8 repository
RUN \
    echo "===> add webupd8 repository..."  && \
    echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list  && \
    echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list  && \
    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886  && \
    apt-get update  && \
    \
    \
    echo "===> install Java"  && \
    echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections  && \
    echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections  && \
    DEBIAN_FRONTEND=noninteractive  apt-get install -y --force-yes oracle-java8-installer oracle-java8-set-default  && \
    \
    \
    echo "===> clean up..."  && \
    rm -rf /var/cache/oracle-jdk8-installer  && \
    apt-get clean  && \
    rm -rf /var/lib/apt/lists/*

      

Build it:



 $ docker build -t t .

      

The result is obtained after the following:

 $ docker run t java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
 $ docker run t python -V
Python 2.7.13

      

Update: . If you want to use oracle jdk7, just replace the code installing jdk in dockerfile with the following. Also note that I would prefer to keep two different jdks in different docker containers. Better to reference the java version you want from another image, just name your builds after the content they have, for example: docker build -t py27jdk7

# add webupd8 repository
RUN \
    echo "===> add webupd8 repository..."  && \
    echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list  && \
    echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list  && \
    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886  && \
    apt-get update  && \
    \
    \
    echo "===> install Java"  && \
    echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections  && \
    echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections  && \
    DEBIAN_FRONTEND=noninteractive  apt-get install -y --force-yes oracle-java7-installer oracle-java7-set-default  && \
    \
    \
    echo "===> clean up..."  && \
    rm -rf /var/cache/oracle-jdk7-installer  && \
    apt-get clean  && \
    rm -rf /var/lib/apt/lists/*

      

The Dockerfile was partially taken from here .

+5


source


Either your disk space is really full, you can check that with a command, df -kh

or there is enough disk space, but from inodes, run df -ih

to confirm this (check ifree or iused ).



0


source


This is most likely because the layers in which it was executed apt-get update

were cached and became old.

So tell docker to START again apt-get update

and discard the cached one. Just add --no-cache

to the command docker build

:

docker build --no-cache ....

      

Or if you are using docker-compose

:

docker-compose build --no-cache ...

      

0


source







All Articles