docker-selenium

repository·trunk·Indexed 27 days ago

https://github.com/seleniumhq/docker-selenium

Official Docker images and Helm charts for Selenium Grid. Provides images for Node and Standalone configurations with compatibility matrices for Chrome, Edge, and Firefox. Includes a Helm chart for deploying Selenium Grid to Kubernetes, supporting isolated components, KEDA-based autoscaling with a gRPC external scaler, and custom Ingress configurations.

Tokens
30.1K
Snippets
62
Records
162
Agent score
93%

What's inside docker-selenium

  1. Identify Selenium Grid and Browser Docker images

    trunk

    The docker-selenium repository provides Docker images that package Selenium Grid with specific browser and driver versions. This allows you to run cross-browser tests or pin specific browser versions for compatibility.

    Images are available for:

    • Node (distributed as part of the Grid)
    • Standalone (packaged with both Grid and specific driver/browser versions)

    To use them, identify the required Grid version and browser version from the compatibility matrix, then pull the corresponding image tag.

  2. Run Selenium Grid Hub and Node (Dynamic Grid)

    trunk

    To deploy a full Grid with a Hub and a Dynamic Node on macOS/Linux, create a network and run the containers. Ensure you mount the config.toml to /opt/selenium/docker.toml and mount the Docker socket.

    macOS/Linux Commands:

    $ docker network create grid
    $ docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub selenium/hub:4.46.0-20260707
    $ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub \
        -v ${PWD}/config.toml:/opt/selenium/docker.toml \
        -v ${PWD}/assets:/opt/selenium/assets \
        -v /var/run/docker.sock:/var/run/docker.sock \
        selenium/node-docker:4.46.0-20260707

    Windows PowerShell Commands:

    $ docker network create grid
    $ docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub selenium/hub:4.46.0-20260707
    $ docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub `
        -v ${PWD}/config.toml:/opt/selenium/docker.toml `
        -v ${PWD}/assets:/opt/selenium/assets `
        -v /var/run/docker.sock:/var/run/docker.sock `
        selenium/node-docker:4.46.0-20260707

    To clean up the network after use:

    $ docker network rm grid
  3. Build Docker images from source

    trunk

    To build the images locally, clone the repository and use the make command.

    Basic Build

    $ VERSION=local make build

    Advanced Build Options

    Use the BUILD_ARGS environment variable to pass additional arguments to the Docker context (requires Docker >= 1.9).

    • Set Proxy: BUILD_ARGS="--build-arg http_proxy=http://acme:3128 --build-arg https_proxy=http://acme:3128" make build
    • Set Host UID/GID: BUILD_ARGS="--build-arg UID=$(id -u) --build-arg GID=$(id -g)" make build
    • Set Custom User/Password: BUILD_ARGS="--build-arg SEL_USER=yourseluser --build-arg SEL_PASSWD=welcome" make build
  4. Deploy Selenium Grid to Kubernetes using Helm

    trunk

    To simplify the deployment process and manage Kubernetes objects more easily, you can use the official Helm chart.

    For detailed instructions and configuration options, refer to:

    • The Helm chart README: charts/selenium-grid/README.md
    • The Helm chart CONFIGURATION: charts/selenium-grid/CONFIGURATION.md
  5. Configure Dynamic Grid with config.toml

    trunk

    Selenium Grid 4 supports a 'Dynamic Grid' mode where Docker containers are started on demand for each new session and destroyed upon completion. This can be used in both Standalone and Node roles.

    To use Dynamic Grid, you must provide a config.toml file that maps Docker images to browser capabilities and specifies the Docker daemon URI.

    Important Configuration Details:

    • File Path: In Dynamic Grid images (standalone-docker or node-docker), you must mount your configuration file to /opt/selenium/docker.toml to avoid conflicts with standard browser container configs.
    • Docker Daemon URL:
      • If mounting /var/run/docker.sock, use http://127.0.0.1:2375 (the container uses socat internally).
      • On Windows (without socket mount): Use http://host.docker.internal:2375.
      • On macOS (without socket mount): Install socat and run socat -4 TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock, then use http://host.docker.internal:2375.
    • Environment Variable: If you name your config file something other than docker.toml, set SE_NODE_DOCKER_CONFIG_FILENAME to your filename.
    [docker]
    # Mapping between Docker image and capabilities
    configs = [
        "selenium/standalone-firefox:4.46.0-20260707", '{"browserName": "firefox"}',
        "selenium/standalone-chrome:4.46.0-20260707", '{"browserName": "chrome"}',
        "selenium/standalone-edge:4.46.0-20260707", '{"browserName": "MicrosoftEdge"}'
    ]
    
    # List of Docker host configuration keys to pass to browser containers
    host-config-keys = ["Dns", "DnsOptions", "DnsSearch", "ExtraHosts", "Binds"]
    
    # URL for connecting to the docker daemon
    url = "http://127.0.0.1:2375"
    
    # Docker image used for video recording
    video-image = "selenium/video:ffmpeg-8.1-20260707"
    
    [server]
    # Required if running the node on a separate VM
    host = <ip-from-node-machine>
    port = <port-from-node-machine>
  6. Enable Selenium Grid Autoscaling with KEDA

    trunk

    Selenium Grid can autoscaled browser nodes up or down based on pending requests in the session queue using KEDA.

    • To install KEDA automatically along with the chart, set autoscaling.enabling: true.
    • To use an existing KEDA installation, set autoscaling.enableWithExistingKEDA: true.

    Scaling can be performed using either deployments or jobs. This is controlled by the autoscaling.scalingType setting. The default is job.

  7. Deploy Selenium Grid on Kubernetes using YAML manifests

    trunk
    If you are not using a Helm chart, you can deploy Selenium Grid on Kubernetes by using the reference YAML manifests provided in this repository. These manifests allow you to set up the Selenium Grid infrastructure directly on your Kubernetes cluster.
  8. Set Firefox language and locale

    trunk

    To configure Firefox to use a specific language and locale, you must set profile preferences when creating the WebDriver and install the corresponding language pack as an add-on.

    Python Example

    profile = webdriver.FirefoxProfile()
    profile.set_preference('intl.accept_languages', 'vi-VN,vi')
    profile.set_preference('intl.locale.requested', 'vi-VN,vi')
    options = FirefoxOptions()
    options.profile = profile
    driver = webdriver.Remote(options=options, command_executor="http://selenium-hub:4444/wd/hub")
    webdriver.Firefox.install_addon(driver, "/local/path/to/vi.xpi")
    driver.get('https://google.com')

    Downloading Language Packs

    You can use the provided script NodeFirefox/get_lang_package.sh to download language packs for a specific Firefox version:

    FIREFOX_VERSION=$(docker run --rm --entrypoint="" selenium/node-firefox:latest firefox --version | awk '{print $3}') \\
    && ./NodeFirefox/get_lang_package.sh ${FIREFOX_VERSION} /local/path/to/download
  9. Use Single Node/Standalone 'all-browsers' images

    trunk

    From tag 4.35.0 onwards, you can use images that include all browsers pre-installed:

    • selenium/standalone-all-browsers (Standalone mode)
    • selenium/node-all-browsers (Hub-Node mode)

    Browser Availability by Architecture:

    Browserx86_64 (amd64)aarch64 (arm64)
    Chrome
    Edge
    Firefox
    Chromium

    Configuration:

    • Switch Chrome to Chromium: Set SE_BROWSER_BINARY_LOCATION_CHROME=/usr/bin/chromium.
    • Disable a browser: Use the environment variable SE_NODE_ENABLE_BROWSER_<BROWSER> where <BROWSER> is the name in uppercase (e.g., CHROME, FIREFOX, EDGE). Set to false to disable.

    Supported Suffix Environment Variables:

    • SE_NODE_ENABLE_BROWSER_<BROWSER>
    • SE_NODE_STEREOTYPE
    • SE_NODE_BROWSER_NAME
    • SE_NODE_BROWSER_VERSION
    • SE_NODE_PLATFORM_NAME
    • SE_BROWSER_BINARY_LOCATION
    • SE_NODE_STEREOTYPE_EXTRA
    • SE_NODE_MAX_SESSIONS
  10. Upgrade Chrome and ChromeDriver at runtime or build time

    trunk

    For node-chrome and standalone-chrome images, you can upgrade Chrome and ChromeDriver using two methods.

    Method 1: Runtime Upgrade (Ephemeral)

    Set the SE_UPDATE_CHROME_COMPONENTS environment variable to true when starting the container. Warning: Updated binaries are lost when the container restarts.

    docker run -d -p 4444:4444 -p 5900:5900 --shm-size="2g" -e SE_UPDATE_CHROME_COMPONENTS=true selenium/standalone-chrome:latest

    Method 2: Build Custom Image (Persistent)

    Create a Dockerfile that runs the update script during the build process to bake the latest versions into your image.

    FROM --platform=linux/amd64 selenium/standalone-chrome:latest
    RUN /opt/bin/update-chrome-components.sh

    Then build your image:

    docker buildx build --platform linux/amd64 -t selenium/standalone-chrome:my-latest .
    FROM --platform=linux/amd64 selenium/standalone-chrome:latest
    RUN /opt/bin/update-chrome-components.sh