Selenium in Docker cannot start Chrome: SessionNotCreatedException
selenium.common.exceptions.SessionNotCreatedException: Message: Could not start a new sessionShort 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.
Fix it fast
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 --version2Match what you see, then jump to its fix
- 1
The two --version outputs differ in the first numberChrome and chromedriver have different major versionsFix - 2
The same script works on your laptop but fails only in the containerThe Chrome container has too little shared memoryFix - 3
The error mentions Selenium Manager or a connection problem before any Chrome window startsSelenium Manager cannot download the driver from inside the containerFix
- 1
What does the error look like?
selenium.common.exceptions.SessionNotCreatedException: Message: Could not start a new sessionResponse 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 Version2Fix
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
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/shm2Fix
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-chrome3Verify
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
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/chromedriver3Verify
Run the script again; the session starts without a download step.
python script.pyConfirmed by selenium.dev
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
Related fixes
Servers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
pip install cryptography tries to compile and fails in a Docker build
fatal error: 'openssl/aes.h' file not found
cryptography ships prebuilt wheels.
3 causes, each with a fixServers
Docker build fails with apk: not found in a Python or Ubuntu image
/bin/sh: 1: apk: not found
apk is the package manager of Alpine Linux only.
2 causes, each with a fixServers
Docker cannot find manage.py or Permission denied on '/manage.py'
PermissionError: [Errno 13] Permission denied: '/manage.py'
The container is looking for manage.py in a directory where the file is not.
3 causes, each with a fixServers
Compose cannot start the service: exec "python manage.py runserver" failed
starting container process caused: exec: "python manage.py runserver
The container runtime was asked to run a program literally named 'python manage.py runserver', including the spaces.
2 causes, each with a fixServers
docker logs prints nothing for a Flask or Python container
the output appears only after the app exits, or in large delayed bursts
docker logs only shows what the process writes to standard output and standard error.
2 causes, each with a fix