Docker selenium: Chrome timeout in headless mode

I am running selenium inside docker and getting this error on this call: driver.get(URL)

Traceback (most recent call last):
  File "esdm.py", line 244, in <module>
    upload_to_esdm(browser, version_url, args.im_file, args.build, args.user_name, args.password, args.apps_file)
  File "esdm.py", line 78, in upload_to_esdm
    browser.get(version_url)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_CONNECTION_TIMED_OUT
  (Session info: headless chrome=87.0.4280.66)

This is my code:

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--js-flags=--max-old-space-size=8196')

driver = webdriver.Chrome(options=chrome_options)
driver.set_window_size(1920, 1080)
driver.get(URL)

And my Dockerfile:

FROM ubuntu:18.04
WORKDIR /src
COPY . /src
RUN apt-get -y update
RUN apt-get install -y python3 python3-pip  chromium-chromedriver
# set display port to avoid a crash
ENV DISPLAY=:99

RUN pip3 install selenium
ENTRYPOINT "/bin/bash"

This works properly in windows, but when running in docker it doesn’t

Source: Dockerfile Questions

LEAVE A COMMENT