How to install openjdk on seleniarm/standalone-chromium (debian)

Viewed 117

I need to run both selenium and OpenJdk. I have a current Dockerfile that does work on M1 Mac which as the ARM architecture, (below). But the JDK version that it uses is 11.0.14+9-post-Debian-1deb11u1:

FROM seleniarm/standalone-chromium:101.0.4951.41-chromedriver-101.0.4951.41-20220429

ENV CHROMEDRIVER_PORT 4444
ENV CHROMEDRIVER_WHITELISTED_IPS "127.0.0.1"
ENV CHROMEDRIVER_URL_BASE ''
EXPOSE 4444

EXPOSE 8080
EXPOSE 5005
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar

ENTRYPOINT ["java","-jar", "-Xmx600m","/app.jar"]

My prior Dockerfile is:

FROM maven:3.6.3-openjdk-15

# Google Chrome

ARG CHROME_VERSION=96.0.4664.45-1
ADD google-chrome.repo /etc/yum.repos.d/google-chrome.repo
RUN microdnf install -y google-chrome-stable-$CHROME_VERSION \
    && sed -i 's/"$HERE\/chrome"/"$HERE\/chrome" --no-sandbox/g' /opt/google/chrome/google-chrome

## ChromeDriver

ARG CHROME_DRIVER_VERSION=96.0.4664.45
RUN microdnf install -y unzip \
    && curl -s -o /tmp/chromedriver.zip https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip \
    && unzip /tmp/chromedriver.zip -d /opt \
    && rm /tmp/chromedriver.zip \
    && mv /opt/chromedriver /opt/chromedriver-$CHROME_DRIVER_VERSION \
    && chmod 755 /opt/chromedriver-$CHROME_DRIVER_VERSION \
    && ln -s /opt/chromedriver-$CHROME_DRIVER_VERSION /usr/bin/chromedriver

ENV CHROMEDRIVER_PORT 4444
ENV CHROMEDRIVER_WHITELISTED_IPS "127.0.0.1"
ENV CHROMEDRIVER_URL_BASE ''
EXPOSE 4444

EXPOSE 8080
EXPOSE 5005
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar", "-Xmx600m","/app.jar"]

Note that FROM maven:3.6.3-openjdk-15 naturally says the jdk version and allows that. But I do not know how to achieve this with standalone-chromium. Does anyone know how to install openjdk (in Docker) with a given version in this case?

1 Answers

I'm not exactly sure what your goal is, whether you're intending to run a Selenium server alongside some other JAR file or if you're just looking to use some of the components from seleniarm/standalone-chromium. I assume the latter, since ENTRYPOINT appears to override seleniarm/standalone-chromium's call to /opt/entry-point.sh.

Regardless of the specific use-case, here's what you can do to install a different OpenJDK:

FROM seleniarm/standalone-chromium:latest

USER root

COPY openjdk-15.0.2_linux-aarch64_bin.tar.gz /opt

RUN mkdir -p /opt/jdk \
#  && curl -L https://download.java.net/java/GA/jdk15.0.2/0d1cfde4252546c6931946de8db48ee2/7/GPL/openjdk-15.0.2_linux-aarch64_bin.tar.gz -o /opt/openjdk-15.0.2_linux-aarch64_bin.tar.gz \
  && cd /opt/jdk && tar xvfz /opt/openjdk-15.0.2_linux-aarch64_bin.tar.gz \
  && export PATH=/opt/jdk/jdk-15.0.2/bin:$PATH \
  #&& echo "export PATH=/opt/jdk/jdk-15.0.2/bin:$PATH" >> /home/seluser/.bashrc \
  #&& echo "export PATH=/opt/jdk/jdk-15.0.2/bin:$PATH" >> /root/.bashrc \
  && rm /usr/bin/java \
  && ln -s /opt/jdk/jdk-15.0.2/bin/java /usr/bin/java \
  && java -version

ENV CHROMEDRIVER_PORT 4444
ENV CHROMEDRIVER_WHITELISTED_IPS "127.0.0.1"
ENV CHROMEDRIVER_URL_BASE ''
EXPOSE 4444

EXPOSE 8080
EXPOSE 5005

USER 1200

#ARG JAR_FILE=target/*.jar
#COPY ${JAR_FILE} app.jar

ENTRYPOINT ["java","-version"]

Then build the container image:

$ docker build -t local/jdk15:latest .

And then run it and get the java version output:

$ docker run --rm -it local/jdk15:latest
openjdk version "15.0.2" 2021-01-19
OpenJDK Runtime Environment (build 15.0.2+7-27)
OpenJDK 64-Bit Server VM (build 15.0.2+7-27, mixed mode)

I left some of the commented script to show what didn't work. Setting the PATH in the .bashrc worked when bashing into the container, but it didn't work with ENTRYPOINT. Instead, creating a symlink to the /usr/bin/java location resolved the issues. Note that this replaces the default Java installation launcher, and this should not be a problem within a container image.

I also copied a downloaded JDK tarball while debugging as this is faster than downloading the JDK each time we rebuild. In production, just comment out the COPY command and uncomment the curl line, which downloads OpenJDK 15 and places it in the /opt folder.

You can also uncomment the commands that copy your JAR file to the container image. I didn't have a JAR file to test with, but this should help get you started. Hope this helps.

Related