I use the following docker-compose.yml to run jupyter notebook based on jupyter/datascience-notebook:87210526f381 and selenium/node-chrome:
version: '3'
services:
selenium-hub:
image: selenium/hub:3.141.59-dubnium
container_name: selenium-hub
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome:3.141.59-dubnium
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
networks:
- backend
nbdatascience:
container_name: nbdatascience
image: aabor/nbdatascience
build: nbdatascience/.
volumes:
- /home/$USER/py:/home/jovyan/work/py
- /home/$USER/.jupyter:/home/jovyan/.jupyter
ports:
- "10000:8888"
environment:
- TZ="Europe/Kiev"
restart: always
networks:
- backend
depends_on:
- chrome
networks:
backend:
driver: bridge
When all these containers up selenium hub is accessible at http://localhost:4444/, and jupyter lab at http://localhost:10000/lab.
I am trying to open web browser session from notebook executing the following python script:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities.CHROME
driver = webdriver.Remote(command_executor='localhost:4444', desired_capabilities=cap)
which gives me error message:
HTTPConnectionPool(host='localhost', port=4444): Max retries exceeded with url: /session (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4c17137278>: Failed to establish a new connection: [Errno 111] Connection refused',))
Correction: running this python script resolves the problem, driver is created and it is possible to navigate the Internet in headless mode:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities.CHROME
driver = webdriver.Remote(command_executor='http://selenium-hub:4444/wd/hub',desired_capabilities=cap)
How do I open connection to selenium chrome running in another docker container? The documentation in SeleniumHQ/docker-selenium lacks these details.
The documentation on docker network says that "Once connected, the containers can communicate using only another container’s IP address or name", so is it possible to call another container by name in python script, for example: driver = webdriver.Remote(command_executor='chrome', desired_capabilities=cap). I tried this command, but it gives me the same error: "connection refused".
lointerface different than localhost that are using the other containers, because they have declaredbackendnetwork. So, try to addnetworks: - backendto selenium-hub. If it doesn't work, addnetwork_mode: hostto all of them.