I'm trying to use Selenium inside a Docker container but after running the docker container the console stays stuck at
INFO [Standalone.execute] - Started Selenium Standalone 4.4.0 (revision e5c75ed026a): http://172.18.0.2:4444
The configuration is pretty simple as I'm trying to just take a screenshot of the web page. My files are
docker-compose.yml
version: '3.3'
services:
selenium:
image: selenium/standalone-chrome
ports:
- 4444:4444
restart: always
app:
build:
context: .
volumes:
- ./app:/app
command: sh -c "python3 bot.py"
depends_on:
- selenium
Dockerfile
FROM python:3.10-alpine
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
RUN mkdir /app
COPY ./app /app
WORKDIR /app
python app
from time import sleep
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium import webdriver
sleep(5)
driver = webdriver.Remote('http://selenium:4444/wd/hub',desired_capabilities=DesiredCapabilities.CHROME)
driver.get('https://python.org')
driver.save_screenshot('screenshot.png')
Selenium seems to run correctly as I got the message INFO success: selenium-standalone entered RUNNING state, process has stayed up for > than 0 seconds (startsecs) and I'm able to reach http://172.18.0.2:4444/ui#
I've also noticed that if I let run enough time the container, it rise the following error
[urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='172.18.0.2', port=4444): Max retries exceeded with url: /wd/hub/session](urllib3.exceptions.maxretryerror: httpconnectionpool(host='172.18.0.2', port=4444): max retries exceeded with url: /wd/hub/session (caused by connecttimeouterror(<urllib3.connection.httpconnection object at 0x7f85ac015900>, 'connection to 172.18.0.2 timed out.)