I am desperately trying to containerise my web scraping app (in python). It is using Selenium.
I'm receiving an error which indicates that the chromedriver binary needs to run as a REGULAR user.
How can I configure this in a dockerfile? The error Im getting is
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable may have wrong permissions. Please see https://chromedriver.chromium.org/home
But when I read the chromedriver site I can see the root cause is that it is running the driver as root, and it doesn't like that.
Here is my dockerfile already:
#FROM python:3.9-buster
FROM --platform=linux/amd64 python:3.10-buster
#FROM --platform=linux/arm64/v8 python:3.9-buster
# FROM --platform=linux/amd64 python:3.9
# FROM selenium/node-chrome
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
RUN apt-get update \
&& apt-get -y install gcc make \
&& rm -rf /var/lib/apt/lists/*s
# RUN apt-get update
RUN apt-get install -y xvfb
RUN 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
RUN apt-get install -y chromium
## RUN apt-get install -y chromium-browser
RUN apt-get install chromium-driver
# RUN apt-get install -y google-chrome-stable
# install chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
# RUN dpkg -i google-chrome-stable_current_amd64.deb --fix-missing; apt-get -fy install
RUN wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
RUN apt-get install -yqq unzip
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update
RUN apt-get update && apt-get install -y wget bzip2 libxtst6 packagekit-gtk3-module libx11-xcb-dev libdbus-glib-1-2 libxt6 libpci-dev && rm -rf /var/lib/apt/lists/*
RUN export PATH=$PATH:'/usr/local/bin/chromedriver'
#download and install chrome
RUN apt update -y
RUN apt install -y google-chrome-stable
RUN apt-get install -y google-chrome-stable
RUN python3 --version
RUN pip3 --version
RUN pip install --no-cache-dir --upgrade pip
RUN apt-get install -y libglib2.0-0 libnss3 libgconf-2-4 libfontconfig1
# COPY chromedriver "/usr/local/bin"
#install python dependencies
COPY requirements.txt requirements.txt
RUN pip install -r ./requirements.txt
#some envs
ENV APP_HOME /app
#set workspace
WORKDIR ${APP_HOME}
RUN chmod -x "/usr/bin/google-chrome"
RUN chmod -x "/usr/local/bin/chromedriver"
#copy local files
COPY . ${APP_HOME}
CMD ["python", "/app/main.py"]