2
votes

I'm running two docker containers as follows:

one is for selenium/standalone-chrome

$ docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome

and the main container uses host networking to connect to MySQL which is running on localhost

$ docker run --rm --network="host" $(IMAGE_REPO)

but when I tried to initiate the driver in the main container

from selenium import webdriver
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', 
                desired_capabilities=webdriver.DesiredCapabilities.CHROME)

I got error message which is either

urllib3.exceptions.ProtocolError: ('Connection aborted.', BadStatusLine("''",))

or

urllib3.exceptions.ProtocolError: ('Connection aborted.', error(104, 'Connection reset by peer'))

did I forget anything / any parameters when trying to establish the containers? or the value passing to command_executor should not be 'http://127.0.0.1:4444/wd/hub'?

I also tried to use docker bridge networking, but then I have no idea how to connect to MySQL server on localhost

SQLALCHEMY_URI = '{driver}://{user}:{pwd}@{host}/{db}?charset=utf8' \
.format(
    driver='mysql+pymysql',
    host='127.0.0.1:3306',
    user='root',
    pwd='0000',
    db='default'
)
1
Check permission of the user that executes the script. - Jhovanny Uribe
Which version of OS you are using? Have your tried command_executor=localhost:4444/wd/hub? - Light.G
@Light.G I'm using Ubuntu 16.04 running on VirtualBox with bridged adapter. I did try localhost but it ended in the same result. More information here: The Dockerfile of the image only has ENTRYPOINT ["python", "main.py"] and If I firstly run bash with the main container, and execute the same python file, there's no problem at all. But it fails if I directly run the container. - Chu-Hsuan Lee

1 Answers

0
votes

Update the following libraries in your Dockerfile:

Set Selenium library version to 3.3.1 (selenium==3.3.1).

i.e: Make use of a Selenium image, whose version is 3.3.1.

Use selenium/node-chrome:3.3.1 instead of selenium/node-chrome:3.141.59-gold