Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dockerfile with chromedriver
# See https://codeship.com/documentation/docker/browser-testing/
FROM myapp:base
# We need wget to set up the PPA and xvfb to have a virtual screen and unzip to install the Chromedriver
RUN apt-get install -y wget xvfb unzip
# Set up the Chrome PPA
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
# Update the package list and install chrome
RUN apt-get update -y
RUN apt-get install -y google-chrome-stable
# Set up Chromedriver Environment variables
ENV CHROMEDRIVER_VERSION 2.19
ENV CHROMEDRIVER_DIR /chromedriver
RUN mkdir $CHROMEDRIVER_DIR
# Download and install Chromedriver
RUN wget -q --continue -P $CHROMEDRIVER_DIR "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"
RUN unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR
# Put Chromedriver into the PATH
ENV PATH $CHROMEDRIVER_DIR:$PATH
@Faq
Copy link

Faq commented Jun 7, 2022

This ^^ approach will not work for the long term. If you were to install Google Chrome on most platforms today, your version would be 101.xxx.xxx.xxx -- a version 97 chromedriver won't work with today's Chrome without having to re-determine the chromedriver version and update the Dockerfile accordingly.

Currently, I do this:

RUN apt-get update && \
    apt-get install -y gnupg wget curl unzip --no-install-recommends && \
    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.d/google.list && \
    apt-get update -y && \
    apt-get install -y google-chrome-stable && \
    CHROME_VERSION=$(google-chrome --product-version | grep -o "[^\.]*\.[^\.]*\.[^\.]*") && \
    CHROMEDRIVER_VERSION=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION") && \
    wget -q --continue -P /chromedriver "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip" && \
    unzip /chromedriver/chromedriver* -d /usr/local/bin/

It has worked consistently for several months over several Chrome updates.

Thank You @mnaumann-plenty, saved my day.

This is up to date version what worked for me with ruby container as it sets correct path with: /usr/local/bin/
Now in container chromedriver responds to: chromedriver -v
And updated it a bit https://gist.github.com/Faq/8821c5fd18dd01da4f80d7435158096d

@KexoTV
Copy link

KexoTV commented Aug 31, 2022

No longer works, i get this error:

#6 85.98 -----END PGP PUBLIC KEY BLOCK-----
#6 85.99 gpg: keyring '/etc/apt/trusted.gpg.d/google.gpg' created
#6 85.99 gpg: no valid OpenPGP data found.
#6 85.99 gpg: Total number processed: 0

@Shk337
Copy link

Shk337 commented Sep 14, 2022

Nono, dude @KexoTV

RUN apt-get update && \
    apt-get install -y gnupg wget curl unzip --no-install-recommends && \
    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.d/google.list && \
    apt-get update -y && \
    apt-get install -y google-chrome-stable && \
    CHROME_VERSION=$(google-chrome --product-version | grep -o "[^\.]*\.[^\.]*\.[^\.]*") && \
    CHROMEDRIVER_VERSION=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION") && \
    wget -q --continue -P /chromedriver "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip" && \
    unzip /chromedriver/chromedriver* -d /usr/local/bin/

its work anyway,

@KexoTV
Copy link

KexoTV commented Sep 16, 2022

this works ty

Nono, dude @KexoTV

RUN apt-get update && \
    apt-get install -y gnupg wget curl unzip --no-install-recommends && \
    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.d/google.list && \
    apt-get update -y && \
    apt-get install -y google-chrome-stable && \
    CHROME_VERSION=$(google-chrome --product-version | grep -o "[^\.]*\.[^\.]*\.[^\.]*") && \
    CHROMEDRIVER_VERSION=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION") && \
    wget -q --continue -P /chromedriver "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip" && \
    unzip /chromedriver/chromedriver* -d /usr/local/bin/

its work anyway,

@bjarneschroeder
Copy link

bjarneschroeder commented Sep 21, 2022

Nono, dude @KexoTV

RUN apt-get update && \
    apt-get install -y gnupg wget curl unzip --no-install-recommends && \
    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.d/google.list && \
    apt-get update -y && \
    apt-get install -y google-chrome-stable && \
    CHROME_VERSION=$(google-chrome --product-version | grep -o "[^\.]*\.[^\.]*\.[^\.]*") && \
    CHROMEDRIVER_VERSION=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION") && \
    wget -q --continue -P /chromedriver "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip" && \
    unzip /chromedriver/chromedriver* -d /usr/local/bin/

its work anyway,

No longer works for me:

 => [internal] load build definition from Dockerfile                                                                                                                                            0.0s
 => => transferring dockerfile: 1.79kB                                                                                                                                                          0.0s
 => [internal] load .dockerignore                                                                                                                                                               0.0s
 => => transferring context: 35B                                                                                                                                                                0.0s
 => [internal] load metadata for docker.io/library/python:3.10                                                                                                                                  1.2s
 => CACHED [ 1/11] FROM docker.io/library/python:3.10@sha256:e9c35537103a2801a30b15a77d4a56b35532c964489b125ec1ff24f3d5b53409                                                                   0.0s
 => => resolve docker.io/library/python:3.10@sha256:e9c35537103a2801a30b15a77d4a56b35532c964489b125ec1ff24f3d5b53409                                                                            0.0s
 => [internal] load build context                                                                                                                                                               0.0s
 => => transferring context: 1.17kB                                                                                                                                                             0.0s
 => ERROR [ 2/11] RUN apt-get update &&     apt-get install -y gnupg wget curl unzip --no-install-recommends &&     wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-k  4.7s
------                                                                                                                                                                                               
 > [ 2/11] RUN apt-get update &&     apt-get install -y gnupg wget curl unzip --no-install-recommends &&     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.d/google.list &&     apt-get update -y &&     apt-get install -y google-chrome-stable &&     CHROME_VERSION=$(google-chrome --product-version | grep -o "[^\.]*\.[^\.]*\.[^\.]*") &&     CHROMEDRIVER_VERSION=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION") &&     wget -q --continue -P /chromedriver "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip" &&     unzip /chromedriver/chromedriver* -d /usr/local/bin/:             
#5 0.269 Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]                                                                                                                              
#5 0.337 Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
#5 0.358 Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
#5 0.410 Get:4 http://deb.debian.org/debian bullseye/main arm64 Packages [8071 kB]
#5 1.744 Get:5 http://deb.debian.org/debian-security bullseye-security/main arm64 Packages [182 kB]
#5 1.769 Get:6 http://deb.debian.org/debian bullseye-updates/main arm64 Packages [2604 B]
#5 2.391 Fetched 8464 kB in 2s (3813 kB/s)
#5 2.391 Reading package lists...
#5 2.658 Reading package lists...
#5 2.919 Building dependency tree...
#5 2.991 Reading state information...
#5 3.074 curl is already the newest version (7.74.0-1.3+deb11u3).
#5 3.074 gnupg is already the newest version (2.2.27-2+deb11u2).
#5 3.074 unzip is already the newest version (6.0-26+deb11u1).
#5 3.074 wget is already the newest version (1.21-1+deb11u1).
#5 3.074 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
#5 3.113 Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
#5 3.685 OK
#5 3.759 Hit:1 http://deb.debian.org/debian bullseye InRelease
#5 3.777 Hit:2 http://deb.debian.org/debian-security bullseye-security InRelease
#5 3.804 Hit:3 http://deb.debian.org/debian bullseye-updates InRelease
#5 3.912 Get:4 http://dl.google.com/linux/chrome/deb stable InRelease [1811 B]
#5 4.029 Fetched 1811 B in 0s (5594 B/s)
#5 4.029 Reading package lists...
#5 4.289 Reading package lists...
#5 4.543 Building dependency tree...
#5 4.611 Reading state information...
#5 4.657 E: Unable to locate package google-chrome-stable

Update: I dug into the problem a little bit more and figured out that the command only does not work on my Docker instance running on my M1 Mac. I guess it has to do with this?
https://askubuntu.com/questions/1383789/install-chrome-on-ubuntu-debian-with-arm64

The command still works on docker instances on other devices. 👍

@mnaumann-plenty
Copy link

mnaumann-plenty commented Sep 21, 2022

@bjarneschroeder :
That seems likely. You can likely locally amend the solution to be geared toward Chromium, specifically these two lines:

    apt-get install -y google-chrome-stable && \
    CHROME_VERSION=$(google-chrome --product-version | grep -o "[^\.]*\.[^\.]*\.[^\.]*") && \

...having the first of the two install Chromium and the second to use the Chromium executable to yield the product version. I haven't explored this locally but exchanging Chromium for Chrome ought to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment