0

I have a Dockerfile that already works in openjdk:8 but I am trying to convert it to alpine. It is giving me some troubles. The application was made in Java and uses Selenium. This is my current code:

FROM openjdk:8-jdk-alpine

RUN apk update \
    && apk fetch gnupg \
    && apk add --virtual \
    curl wget xvfb unzip gnupg \
    && gpg --list-keys

ARG CHROME_DRIVER_VERSION=85.0.4183.87
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb [arch=amd64]  http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
    && apk update \
    && apk add google-chrome-stable \
    && apk cache clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
    && wget https://chromedriver.storage.googleapis.com/${CHROME_DRIVER_VERSION}/chromedriver_linux64.zip \
    && unzip chromedriver_linux64.zip \
    && mv chromedriver /usr/bin/chromedriver \
    && chown root:root /usr/bin/chromedriver \
    && chmod +x /usr/bin/chromedriver

EXPOSE 42052
.
.
.

I tried to add gnupg like I found in here: Docker: Using apt-key with alpine image

But it does not work, I just get an error: /bin/sh: gpg: not found

If I removed it, I just get the issue with apt-key that is not found. What is the alternative in alpine or what changes do I have to do to my docker file to work again.

Thanks in advance

Linkavich14
  • 243
  • 1
  • 5
  • 15

2 Answers2

1

Apparently the Chrome .deb file won't work on Alpine. So it needs Chromium to work. If you are already using the ChromeDriver in the Java code it will work without making any changes like in my case.

FROM openjdk:8-jdk-alpine

RUN apk update && apk add --no-cache bash \
    alsa-lib \
    at-spi2-atk \
    atk \
    cairo \
    cups-libs \
    dbus-libs \
    eudev-libs \
    expat \
    flac \
    gdk-pixbuf \
    glib \
    libgcc \
    libjpeg-turbo \
    libpng \
    libwebp \
    libx11 \
    libxcomposite \
    libxdamage \
    libxext \
    libxfixes \
    tzdata \
    libexif \
    udev \
    xvfb \
    zlib-dev \
    chromium \
    chromium-chromedriver \
    && rm -rf /var/cache/apk/* \
    /usr/share/man \
    /tmp/*

RUN mkdir -p /data && adduser -D chrome \
    && chown -R chrome:chrome /data
USER chrome

.
.
.

If you are going to add create folders and/or add files like in my case, just add USER root to work

It will work the same as the openjdk:8 version.

Linkavich14
  • 243
  • 1
  • 5
  • 15
0

Actually alpine version in answer post to correct work has to add in code:

chromeOptions.setBinary("/usr/bin/chromium-browser");
Pawel W
  • 101
  • 1
  • 1
  • 12