1

I have a set up of Protractor, for which I need java in my Dockerfile to run the selenium-server.jar file.

Here is my Dockerfile

FROM node:latest


ENV CHROME_VERSION "google-chrome-stable"
RUN sed -i -- 's&deb http://deb.debian.org/debian jessie-updates main&#deb http://deb.debian.org/debian jessie-updates main&g' /etc/apt/sources.list \
  && apt-get -o Acquire::Check-Valid-Until=false update && apt-get -o Acquire::Check-Valid-Until=false install wget -y
ENV CHROME_VERSION "google-chrome-stable"
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
  && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list \
  && apt-get -o Acquire::Check-Valid-Until=false update && apt-get -qqy --allow-unauthenticated install ${CHROME_VERSION:-google-chrome-stable}



# Add the dependencies to get the xenial apt sources
RUN echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
RUN echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
RUN apt-get -y update

# Add these silent accept - since oracle installer asks for permission to install java-version-8
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 seen true" | debconf-set-selections

# Install java-8 


RUN apt install -y oracle-java8-installer && apt install oracle-java8-set-default

This set up was working fine until yesterday but since then I've been getting this error

 download failed
Oracle JDK 8 is NOT installed.
dpkg: error processing package oracle-java8-installer (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 oracle-java8-installer
E: Sub-process /usr/bin/dpkg returned an error code (1)
The command '/bin/sh -c apt install -y oracle-java8-installer && apt install oracle-java8-set-default' returned a non-zero code: 100

Now before marking this question as a duplicate , please see that I have gone through a lot of similar SO posts and applied all the changes mentioned but the error still persists or I get a new error, which circles back to this unable to download error.

I have tried the solutions mentioned in this, this, this and this, this, this, this but haven't been able to solve it.

The complete log file is here. If required, I can post the error that I got when trying to apply the solutions mentioned.

Looking for any pointers to solve this issue.

demouser123
  • 4,108
  • 9
  • 50
  • 82
  • Any specific reason on why you want to run java on a node image? – Esteban Garcia Apr 18 '19 at 14:22
  • As I have stated - I need Java to start the `selenium-server.jar` file - It needs to be started before I can execute the Protractor tests. On local, this explicit setting using a `directConnect` flag. However, when running in a CI-CD pipeline, the latter fails. – demouser123 Apr 18 '19 at 14:27

2 Answers2

0

Docker will remember the result of running each command unless you explicitly tell it not to (docker build --no-cache). In particular, it will skip over running the apt-get update step if it thinks it’s already done this.

Meanwhile, the Debian and Ubuntu repositories update frequently, and when they update, they remove old versions of packages. This means that if you’re using yesterday’s version of the package cache, you’ll get “download failed” errors like you see until you re-run apt-get update.

In a Docker context, the correct answer to this is to always run apt-get update and apt-get install in the same RUN step. You might change the end of your Dockerfile to look like

RUN apt-get update -y \
 && apt install oracle-java8-installer oracle-java8-set-default

Once you’ve gotten past the initial development stage it’s probably good practice to just have a single apt install command in your Dockerfile that does one pass at installing all of the runtime dependencies you need.

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • Thanks for the pointers. However, even changing the line that you mentioned gives me the same output (with `--no-cache` and `apt-get update and install` in same line. – demouser123 Apr 18 '19 at 14:36
0

Do you really need to have oracle jdk? In the pass, I used the content of Dockerfile from openjdk to build an image from node and having java installed: https://github.com/docker-library/openjdk/blob/master/8/jdk/Dockerfile

Nevertheless, in your case, I would build a centralized selenium server or use a directConnect in CI pipeline.

HTN
  • 3,388
  • 1
  • 8
  • 18