Chrome crashes no matter what in Selenium docker image,

1,115 views
Skip to first unread message

Manu Adina-Zada

unread,
Jan 26, 2023, 11:45:02 PM1/26/23
to Selenium Users
Hi,

I've been trying to run Chrome in the selenium docker image (--platform=linux/amd64 selenium/standalone-chrome), and no matter what I try it keeps crashing inside the container.

I'm using python to start the chrome,
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--no-sandbox")
driver = webdriver.Chrome(options=options)

I've tried many options, and these 3 options are the ones that suggested the most, and Chrome still crashes.

However, for the final container that I'm going to run - chrome needs to run without the headless mode. The whole idea is to run chrome inside the container and run an application in the browser window to collect some data.

I get the following error,
Traceback (most recent call last):
  File "asset-audit-chrome.py", line 23, in <module>
    driver = webdriver.Chrome(options=options)
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    super().__init__(
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chromium/webdriver.py", line 106, in __init__
    super().__init__(
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 288, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 381, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
  (chrome not reachable)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Any help would be appreciated, I've spent countless hours in order to try to get any form of chrome running in the docker selenium container.. to no avail.

Thanks!
Manu



SuperKevy

unread,
Jan 27, 2023, 2:55:11 PM1/27/23
to Selenium Users

Serguei Kouzmine

unread,
Jan 30, 2023, 8:49:41 PM1/30/23
to Selenium Users

I believe you can run selenium +  chromium in alpine image headless

Manu Adina-Zada

unread,
Feb 2, 2023, 9:39:21 PM2/2/23
to Selenium Users
Thanks for trying to help guys,

After few days, I discovered that it works if I run my python by going to using the terminal inside the container.
The whole time, I had a CMD ["python3", "script.py"] in the end of the Dockerfile, and for whatever reason it wouldn't work at all.
I do need this step to be automated, and so I do need to have the CMD inside the Dockerfile to automatically launch the python script..
Any ideas on how to make it work or what the reason of this might be?

- Initially I thought it was some time of race condition problem, so I tried including,
 1. Sleep in the CMD line of the Dockerfile i.e. CMD sleep 10; python3 script.py
 2. Sleep in the python script time.sleep(10) before "driver = webdriver.Chrome(options=options)" line.

Both have not worked, the chrome still crashes when attempting to launch on start with the CMD command in the Dockerfile.
Any help would be appreciated, thanks!
- Manu

SuperKevy

unread,
Feb 3, 2023, 7:28:37 PM2/3/23
to Selenium Users
See  https://runnable.com/docker/python/dockerize-your-python-application
I assume chrome and chromedriver are synched and work in the image.

Manu Adina-Zada

unread,
Feb 13, 2023, 9:35:36 PM2/13/23
to Selenium Users
As I've stated previously, the script works fine if I launch the container first with "docker run ... etc", and then use "docker exec .. " to start my python script , or even going into the container's terminal and starting the script through there is fine.

The issue lies with starting the script on startup by having CMD or ENTRYPOINT to start the script on startup.

Any help would be appreciated! Thanks
Reply all
Reply to author
Forward
0 new messages