Chrome & ChromeDriver in Docker

When I containerised Selenium crawlers in the past I normally used a remote driver connection from the crawler to Selenium, running a separate Docker image with Selenium and accessing it via port 4444. This has proven to be a robust design. However, it does mean two containers rather than just one, leading to a higher maintenance burden and elevated resource requirements.

What about simply embedding Chrome and ChromeDriver directly into the crawler image? It requires a bit more work, but it’s worth it. The critical point is ensuring compatible versions of Chrome and ChromeDriver.

Recent distributions of Chrome and ChromeDriver can be found here. The Dockerfile extract below installs from that location.

RUN apt-get update -qq -y && \
    apt-get install -y \
        libasound2 \
        libatk-bridge2.0-0 \
        libgtk-4-1 \
        libnss3 \
        xdg-utils \
        wget && \
    wget -q -O && \
    unzip && \
    rm && \
    mv chrome-linux64 /opt/chrome/ && \
    ln -s /opt/chrome/chrome /usr/local/bin/ && \
    wget -q -O && \
    unzip -j chromedriver-linux64/chromedriver && \
    rm && \
    mv chromedriver /usr/local/bin/

Fedora Base Image

The setup above assumes that you are using a Debian base image. Here are the dependencies for images using the dnf or yum package managers.

RUN dnf update -y && \
    dnf install -y \
        wget \
        unzip \
        gtk3 \
        nss \
        atk \
        at-spi2-atk \
        cups-libs \
        libdrm \
        libxkbcommon \
        libXcomposite \
        libXdamage \
        libXrandr && \
    dnf clean all

Launching Selenium


If you’re going to be running a Node application then you’ll want to use a node base image.

FROM node:18

# 🚀 Install Chrome and Chromedriver here!

WORKDIR /usr/src/app
COPY package*.json .


RUN npm install --omit=dev
RUN npm install chromedriver

COPY . .

CMD [ "npm", "start" ]

Setting the CHROMEDRIVER_SKIP_DOWNLOAD environment variable is important to ensure that an incompatible version of ChromeDriver is not installed along with the chromedriver package.

Test with something like this:

import { Builder } from 'selenium-webdriver';
import chrome from 'selenium-webdriver/chrome.js';

console.log("Start the browser.")

let chromeOptions = new chrome.Options();
chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');

let driver = new Builder()


console.log("Open Google.")
await driver.get("");

const html = await driver.getPageSource();


Possibly not all of those options are necessary. The --no-sandbox is required though, otherwise you get an error related to launching Chrome as the root user.


Similarly, for Python you’ll want a python base image.

FROM python:3.11.4

# 🚀 Install Chrome and Chromedriver here!

RUN pip3 install selenium==4.18.1

Test with something like this:

from selenium.webdriver import Chrome, ChromeOptions

options = ChromeOptions()

driver = Chrome(options=options)