Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Selenium in Docker cannot start Chrome: SessionNotCreatedException

Errorselenium.common.exceptions.SessionNotCreatedException: Message: Could not start a new session

Short answer

The driver started but Chrome could not be launched or matched. In containers the usual causes are a Chrome and chromedriver pair with different major versions, too little shared memory for the browser, or Selenium Manager unable to download a driver. Print both versions first, then fix the one that disagrees.

  • Applies to Selenium 4.26 or newer, Python 3.12, Chrome stable
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the Chrome version and the driver version inside the same container that runs the script. The major numbers must match.

    google-chrome --version
    chromedriver --version
  2. 2Match what you see, then jump to its fix

    1. 1The two --version outputs differ in the first numberChrome and chromedriver have different major versionsFix
    2. 2The same script works on your laptop but fails only in the containerThe Chrome container has too little shared memoryFix
    3. 3The error mentions Selenium Manager or a connection problem before any Chrome window startsSelenium Manager cannot download the driver from inside the containerFix

What does the error look like?

  • selenium.common.exceptions.SessionNotCreatedException: Message: Could not start a new session
  • Response code 500

Cause 1 of 3

Chrome and chromedriver have different major versions

1Check

The Selenium Chrome docs say the browser and chromedriver must match in major version. A chromedriver copied into the image long ago, or a base image that updates Chrome but not the driver, drifts apart.

google-chrome --version
chromedriver --version
python -m pip show selenium | grep Version

2Fix

Remove the hand-installed driver and do not pass a Service path. Since Selenium 4.6 Selenium Manager finds the installed browser, downloads the matching driver and caches it. Or pin both in the image deliberately.

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)

3Verify

A session opens and loads a page.

driver.get("https://example.com")
print(driver.title)
driver.quit()

Confirmed by selenium.dev

Did this fix it?

Cause 2 of 3

The Chrome container has too little shared memory

1Check

Docker gives a container a small /dev/shm by default. The docker-selenium project asks you to start browser images with a larger shared memory flag.

docker exec <container> df -h /dev/shm

2Fix

Start the browser container with --shm-size, as the project's quick start shows.

docker run -d -p 4444:4444 --shm-size="2g" selenium/standalone-chrome

3Verify

Connect the script to the grid on port 4444 and open a page.

from selenium import webdriver
driver = webdriver.Remote(command_executor="http://localhost:4444", options=webdriver.ChromeOptions())
driver.get("https://example.com")
print(driver.title)
driver.quit()

Confirmed by github.com

Did this fix it?

Cause 3 of 3

Selenium Manager cannot download the driver from inside the container

1Check

Selenium Manager needs network access to find and download the driver, and a proxy or firewall can block it. Its cache defaults to ~/.cache/selenium, which is empty in a fresh container.

ls ~/.cache/selenium 2>/dev/null
env | grep -E "^SE_|proxy"

2Fix

Allow the network call (set SE_PROXY if you use a proxy), or bake the driver into the image and point Selenium at it with SE_CHROMEDRIVER (Python binding 4.26.0 and later). SE_OFFLINE=true stops all downloads, so use it only when browser and driver are already present.

# Dockerfile
ENV SE_CHROMEDRIVER=/usr/local/bin/chromedriver

3Verify

Run the script again; the session starts without a download step.

python script.py

Confirmed by selenium.dev

Did this fix it?

How do I stop it coming back?

  • Install Chrome and the driver in the same image build step, or let Selenium Manager fetch both, never a mix of the two.
  • Print both versions in CI before the tests run.
  • Give browser containers an explicit shared memory size in every compose file.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.