'Running Selenium in Docker container not headless throws error DevToolsActivePort
I'm running a Selenium webdriver and Chrome browser in my Docker container debian:latest.
I want to have the headless option on the webdriver to be False since I learned running webdriver with a head will reduce the chances my application is determined to be a bot.
When I run my Python script on my desktop, the application works as intended. But when running in the application in the container, I get the error below:
Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
After lots of debugging, I found this only happens when the webdriver is specified to run non "headless". When I run the Docker container with headless set to True, the container works as intended. I suspect this caused by the container not having a monitor/desktop.
Dockerfile
FROM debian:latest
WORKDIR /application
...
# Download Chrome browser file version
ADD https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}-1_amd64.deb \
/google-chrome-stable_${CHROME_VERSION}-1_amd64.deb
COPY . .
RUN apt update -y; \
apt install python3-pip -y; \
pip3 install --upgrade pip; \
pip3 install -r requirements.txt
RUN apt update -y; \
dpkg --install /google-chrome-stable_${CHROME_VERSION}-1_amd64.deb
CMD python3 -m my_application
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
