Docker, Django and Selenium - Selenium unable to connect

前端 未结 3 2099
太阳男子
太阳男子 2020-12-18 12:28

I have Docker configured to run Postgres and Django using docker-compose.yml and it is working fine.

The trouble I am having is with Selenium not being able to conne

3条回答
  •  臣服心动
    2020-12-18 13:07

    I've been struggling with this as well, and I finally found a solution that worked for me. You can try something like this:

    postgis:
      dockerfile: ./docker/postgis/Dockerfile
      build: .
    
    django:
      dockerfile: ./docker/Dockerfile-dev
      build: .
      command: python /app/project/manage.py test my-app
      volumes:
        - .:/app
      ports:
        - "8000:8000"
      links:
        - postgis
        - selenium  # django can access selenium:4444, selenium can access django:8081-8100
      environment:
        - SELENIUM_HOST=http://selenium:4444/wd/hub
        - DJANGO_LIVE_TEST_SERVER_ADDRESS=django:8081-8100  # this gives selenium the correct address
    
    selenium:
      image: selenium/standalone-firefox-debug
      ports:
        - "5900:5900"
    

    I don't think you need to include port 4444 in the selenium config. That port is exposed by default, and there's no need to map it to the host machine, since the django container can access it directly via its link to the selenium container.

    [Edit] I've found you don't need to explicitly expose the 8081 port of the django container either. Also, I used a range of ports for the test server, because if tests are run in parallel, you can get an "Address already in use" error, as discussed here.

提交回复
热议问题