How to connect to remote Selenium drivers within the same docker-compose?

Viewed 273

I ran into a

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='chromedriver', port=4444): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fc2de559bb0>: Failed to establish a new connection: [Errno 111] Connection refused'))

While running Selenium via Python and Docker.

My Connection looks like this:

self.driver = webdriver.Remote(
           command_executor='http://chromedriver:4444/wd/hub',
           options=options
       )

The docker-compose like this:

...
  chromedriver:
    image: selenium/standalone-chrome
    ports:
      - "4444:4444"
    hostname: chromedriver
    shm_size: 2g
  runner:
    image: "kevoooo/twitchfarm-runner:latest"
    entrypoint: "python3 /py-scripts/main.py"
    healthcheck:
        test: python3 /py-scripts/main.py
        interval: 30s
        timeout: 10s
        retries: 5
    environment:
      - DISPLAY=127.0.0.1
      - USER=uname
      - PASS=pass
      - 2FA_KEY=key
    volumes:
      - "chrome-data:/saves/google-chrome"
    depends_on:
      - chromedriver
...

Thanks in advance!

2 Answers

According to https://docs.docker.com/compose/startup-order/ - depends_on only controls the order of service start up. It does not know when the container is ready.

Basically the container readiness state is how a client treats it so it is up to the application that uses the containerized service how to handle service disruption (either cause by the service has not yet started completely or by any fault after the service has started)

So your solution makes the sense. Despite is it rough enough. The better choice would be to have a script that polls endpoint until the success is returned and then proceed with your test code.

I solved it by changing the entrypoint of "runner" to:

    entrypoint: bash -c "sleep 10 && python3 /py-scripts/main.py"

I thought, that was handled by the "depends-on"-clause

Related