Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98773

docker: selenium chrome driver setup

$
0
0

I've tried so many times to set up my docker with selenium and I please need your help.My actual docker file is:

# syntax=docker/dockerfile:1# Comments are provided throughout this file to help you get started.# If you need more help, visit the Dockerfile reference guide at# https://docs.docker.com/go/dockerfile-reference/ARG PYTHON_VERSION=3.11.4FROM python:${PYTHON_VERSION}-slim AS base# Prevents Python from writing pyc files.ENV PYTHONDONTWRITEBYTECODE=1# Keeps Python from buffering stdout and stderr to avoid situations where# the application crashes without emitting any logs due to buffering.ENV PYTHONUNBUFFERED=1WORKDIR /app# Create a non-privileged user that the app will run under.# See https://docs.docker.com/go/dockerfile-user-best-practices/ARG UID=10001RUN adduser \    --disabled-password \    --gecos "" \    --home "/nonexistent" \    --shell "/sbin/nologin" \    --no-create-home \    --uid "${UID}" \    appuser# Download dependencies as a separate step to take advantage of Docker's caching.# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.# Leverage a bind mount to requirements.txt to avoid having to copy them into# into this layer.RUN pip install --upgrade pipRUN --mount=type=cache,target=/root/.cache/pip \    --mount=type=bind,source=requirements.txt,target=requirements.txt \    python -m pip install -r requirements.txt#####################RUN apt-get update RUN apt-get install wget -yRUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils#download and install chromeRUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.debRUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install###################### Set environment variables to prevent Firefox from using a displayENV DISPLAY=:99# Switch to the non-privileged user to run the application.USER appuser# Copy the source code into the container.COPY . .# Expose the port that the application listens on.EXPOSE 8000# Run the application.CMD ["python", "app.py"]

and my code is:

from selenium import webdriver# import chromedriver_binaryfrom webdriver_manager.chrome import ChromeDriverManagerchrome_options = webdriver.ChromeOptions()chrome_options.add_argument("--no-sandbox")chrome_options.add_argument("--disable-dev-shm-usage")chrome_options.add_argument("--headless")chrome_options.add_argument("--disable-audio")# Configure o WebDriver para usar o Selenium Standalone Chromedriver = webdriver.Chrome(ChromeDriverManager().install())

with a compose.yaml like this:

services:  server:    build:      context: .    ports:      - "8000:8000"`

and finally my log:

 Traceback (most recent call last):mercadolivrescraping-server-1  |   File "/app/app.py", line 15, in <module>mercadolivrescraping-server-1  |     driver = webdriver.Chrome(ChromeDriverManager().install())mercadolivrescraping-server-1  |                   mercadolivrescraping-server-1  |          mercadolivrescraping-server-1  |    ^^mercadolivrescraping-server-1  | ^^^^^mercadolivrescraping-server-1  | ^^^^^^^^mercadolivrescraping-server-1  | ^^^^^mercadolivrescraping-server-1  | ^^^^^^mercadolivrescraping-server-1  | ^^^^^mercadolivrescraping-server-1  |   File "/usr/local/lib/python3.11/site-packages/webdriver_manager/chrome.py", line 40, in installmercadolivrescraping-server-1  |     driver_path = self._get_driver_binary_path(self.driver)mercadolivrescraping-server-1  |                  mercadolivrescraping-server-1  |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^mercadolivrescraping-server-1  |   File "/usr/local/lib/python3.11/site-packages/webdriver_manager/core/manager.py", line 41, in _get_driver_binary_pathmercadolivrescraping-server-1  |     binary_path = self._cache_manager.save_file_to_cache(driver, file)mercadolivrescraping-server-1  |                  mercadolivrescraping-server-1  |  ^^^^^^^mercadolivrescraping-server-1  | ^^^^^mercadolivrescraping-server-1  | ^^^^^^^mercadolivrescraping-server-1  | ^^^^^^mercadolivrescraping-server-1  | ^^^^mercadolivrescraping-server-1  | ^^^^^^^^^^^^^^^^^^^^^^^mercadolivrescraping-server-1  |   File "/usr/local/lib/python3.11/site-packages/webdriver_manager/core/driver_cache.py", line 53, in save_file_to_cachemercadolivrescraping-server-1  |     archive = self.save_archive_file(file, path)mercadolivrescraping-server-1  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^mercadolivrescraping-server-1  |   File "/usr/local/lib/python3.11/site-packages/webdriver_manager/core/driver_cache.py", line 46, in save_archive_filemercadolivrescraping-server-1  |     return self._file_manager.save_archive_file(file, path)mercadolivrescraping-server-1  |            ^^^^mercadolivrescraping-server-1  | ^^^^^^^^^^^^^^^^^^^^mercadolivrescraping-server-1  | ^^^^^^^^^mercadolivrescraping-server-1  | ^^^^^^mercadolivrescraping-server-1  | ^^^^^^^mercadolivrescraping-server-1  | ^^mercadolivrescraping-server-1  |   File "/usr/local/lib/python3.11/site-packages/webdriver_manager/core/file_manager.py", line 45, in save_archive_filemercadolivrescraping-server-1  |     mercadolivrescraping-server-1  | os.makedirs(directory, exist_ok=True)mercadolivrescraping-server-1  |   File "<frozen os>", line 215, in makedirsmercadolivrescraping-server-1  |   File "<frozen os>", line 215, in makedirsmercadolivrescraping-server-1  |   File "<frozen os>", line 215, in makedirsmercadolivrescraping-server-1  |   [Previous line repeated 2 more times]mercadolivrescraping-server-1  |   File "<frozen os>", line 225, in makedirsmercadolivrescraping-server-1  | PermissionError: [Errno 13] Permission denied: '/nonexistent'

I've tried install chrome and chrome driver manually and it didn't work, I've tried the chromedriver_binary lib from python with the chrome installed by the dockerfile and it didn't work and I've tried so many things and also didn't work.

Can you please tell me what am I doing wrong and what can I do instead, please? If you need any more information, please ask me.


Viewing all articles
Browse latest Browse all 98773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>