I want to run Selenium in the docker-compose on my Ubuntu server.
I have Dockerfile
FROM python:3.13.1-slim-bookwormENV POETRY_VERSION=2.0.1ENV PYTHONUNBUFFERED=1ENV POETRY_VIRTUALENVS_CREATE=falseENV USER=maSHELL ["/bin/bash", "-o", "pipefail", "-c"]RUN groupadd -r $USER && useradd -r -g $USER -d /opt/$USER $USERRUN apt-get update \&& apt-get install -y --no-install-recommends \ wget \ unzip \ gnupg \ libglib2.0-0 \ libnss3 \ libgconf-2-4 \ libfontconfig1 \ libxcb1 \&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' \&& apt-get -y update \&& apt-get install -y google-chrome-stable \&& apt-get clean \&& rm -rf /var/lib/apt/lists/*# Install poetryRUN pip install --no-cache-dir --upgrade pip \&& pip install --no-cache-dir poetry==${POETRY_VERSION}WORKDIR /opt/$USERRUN mkdir -p /opt/$USER/.cache/selenium && chown -R $USER:$USER /opt/$USER/.cacheCOPY ./poetry.lock ./pyproject.toml ./RUN poetry install --no-interaction --no-cache --no-rootCOPY ignore_list.txt ./COPY app appUSER $USERENTRYPOINT ["poetry", "run", "python", "-m", "app.get_next_predictions"]docker-compose.yaml
services: app: image: portal container_name: portal build: context: . dockerfile: deployments/Dockerfile env_file: - .envand code for running webdriver
def start_browser(portal_config: PortalSettings) -> webdriver.Chrome: options = Options() options.add_experimental_option("useAutomationExtension", False) options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option("detach", True) options.add_argument("--disable-dev-shm-usage") options.add_argument("--disable-extensions") # Disable browser extensions options.add_argument("--disable-crash-reporter") # Disable crash reporting options.add_argument("--disable-infobars") # Disable infobars options.add_argument("--disable-logging") options.add_argument("--disable-background-timer-throttling") options.add_argument("--disable-backgrounding-occluded-windows") options.add_argument("--disable-renderer-backgrounding") options.add_argument("--no-sandbox") options.add_argument("--headless") options.add_argument("--disable-gpu") options.add_argument("--start-maximized") options.add_argument('log-level=3') options.add_experimental_option('excludeSwitches', ['enable-logging']) browser = webdriver.Chrome(options=options) browser.maximize_window() browser.get('https://www.portal.com/login') login(browser, portal_config) return browserWhen I start app I get error
portal | Skipping virtualenv creation, as specified in config file.portal | Traceback (most recent call last):portal | File "<frozen runpy>", line 198, in _run_module_as_mainportal | File "<frozen runpy>", line 88, in _run_codeportal | File "/opt/portal/app/get_next_predictions.py", line 267, in <module>portal | asyncio.run(starter())portal | ~~~~~~~~~~~^^^^^^^^^^^portal | File "/usr/local/lib/python3.13/asyncio/runners.py", line 194, in runportal | return runner.run(main)portal | ~~~~~~~~~~^^^^^^portal | File "/usr/local/lib/python3.13/asyncio/runners.py", line 118, in runportal | return self._loop.run_until_complete(task)portal | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^portal | File "/usr/local/lib/python3.13/asyncio/base_events.py", line 720, in run_until_completeportal | return future.result()portal | ~~~~~~~~~~~~~^^portal | File "/opt/portal/app/get_next_predictions.py", line 252, in starterportal | browser = start_browser(portal_config)portal | File "/opt/portal/app/get_next_predictions.py", line 234, in start_browserportal | browser = webdriver.Chrome(options=options)portal | File "/usr/local/lib/python3.13/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__portal | super().__init__(portal | ~~~~~~~~~~~~~~~~^portal | browser_name=DesiredCapabilities.CHROME["browserName"],portal | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^portal | ...<3 lines>...portal | keep_alive=keep_alive,portal | ^^^^^^^^^^^^^^^^^^^^^^portal | )portal | ^portal | File "/usr/local/lib/python3.13/site-packages/selenium/webdriver/chromium/webdriver.py", line 66, in __init__portal | super().__init__(command_executor=executor, options=options)portal | ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^portal | File "/usr/local/lib/python3.13/site-packages/selenium/webdriver/remote/webdriver.py", line 241, in __init__portal | self.start_session(capabilities)portal | ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^portal | File "/usr/local/lib/python3.13/site-packages/selenium/webdriver/remote/webdriver.py", line 329, in start_sessionportal | response = self.execute(Command.NEW_SESSION, caps)["value"]portal | ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^portal | File "/usr/local/lib/python3.13/site-packages/selenium/webdriver/remote/webdriver.py", line 384, in executeportal | self.error_handler.check_response(response)portal | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^portal | File "/usr/local/lib/python3.13/site-packages/selenium/webdriver/remote/errorhandler.py", line 232, in check_responseportal | raise exception_class(message, screen, stacktrace)portal | selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.portal | (session not created: DevToolsActivePort file doesn't exist)portal | (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)portal | Stacktrace:portal | #0 0x6190ff7701fa <unknown>portal | #1 0x6190ff280810 <unknown>portal | #2 0x6190ff2b7ed8 <unknown>portal | #3 0x6190ff2b3a36 <unknown>portal | #4 0x6190ff2ff816 <unknown>portal | #5 0x6190ff2fee66 <unknown>portal | #6 0x6190ff2f3323 <unknown>portal | #7 0x6190ff2c1de0 <unknown>portal | #8 0x6190ff2c2dbe <unknown>portal | #9 0x6190ff73c12b <unknown>portal | #10 0x6190ff7400c7 <unknown>portal | #11 0x6190ff7296cc <unknown>portal | #12 0x6190ff740c47 <unknown>portal | #13 0x6190ff70e67f <unknown>portal | #14 0x6190ff75f288 <unknown>portal | #15 0x6190ff75f450 <unknown>portal | #16 0x6190ff76f076 <unknown>portal | #17 0x77ca011d31c4 <unknown>Also when I run this code on the my local MacOS (M1) it's work fine.
Upd: It's work when I remove created user... Why? And how can fix it and work with nonroot user.