【问题标题】:Can't connect to selenium-hub from Rails sidekiq with docker-compose.yml无法使用 docker-compose.yml 从 Rails sidekiq 连接到 selenium-hub
【发布时间】:2018-06-15 14:07:49
【问题描述】:

尝试使用 docker-compose 从 sidekiq worker 运行 selenium。 如果我从 rails 任务运行作业,它会很好地工作。但是当我从 sidekiq 运行时它不起作用。 从 sidekiq 运行 Job 时出现此错误。

Errno::EADDRNOTAVAIL: 无法打开与 localhost:4444 的 TCP 连接(无法分配请求的地址 - connect(2) 用于“localhost”端口 4444)

docker-compose.yml

version: '3'
services:
  db:
    image: mysql
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
    depends_on:
      - db

  redis:
    image: redis:latest
    ports:
      - 6379:6379

  sidekiq:
    build: .
    command: bundle exec sidekiq
    volumes:
      - .:/myapp
    depends_on:
      - db
      - redis

  selenium-hub:
    image: selenium/hub:3.12.0-boron
    container_name: selenium-hub
    ports:
      - "4444:4444"
  chrome:
    image: selenium/node-chrome:3.12.0-boron
    depends_on:
      - selenium-hub
    environment:
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444
  firefox:
    image: selenium/node-firefox:3.12.0-boron
    depends_on:
      - selenium-hub
    environment:
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444

请建议我如何解决此问题

【问题讨论】:

    标签: ruby-on-rails ruby selenium docker docker-compose


    【解决方案1】:

    我让它与这样的 docker-compose.yml 一起工作:

    version: '3.3'
    services:
      selenium-hub:
        container_name: selenium_hub
        image: selenium/hub:3.12.0-cobalt
        ports:
          - 4444:4444
        networks:
          - selenium_grid
    
      selenium-chrome:
        container_name: selenium_chrome
        image: selenium/node-chrome:3.12.0-cobalt
        environment:
          - HUB_HOST=selenium_hub
          - HUB_PORT=4444
        volumes:
          - /dev/shm:/dev/shm
        networks:
          - selenium_grid
        depends_on:
          - selenium-hub
    
      selenium-firefox:
        container_name: selenium_firefox
        image: selenium/node-firefox:3.12.0-cobalt
        environment:
          - HUB_HOST=selenium_hub
          - HUB_PORT=4444
        volumes:
          - /dev/shm:/dev/shm
        networks:
          - selenium_grid
        depends_on:
          - selenium-hub
    
    networks:
      selenium_grid:
        driver: bridge
    

    【讨论】:

    • driver:bridge 对我有用。我的问题是我有两个容器服务 A(暴露端口 5000)和 B(试图从端口 5000 中的 A 消费)。我遇到了同样的错误。
    猜你喜欢
    • 2013-01-28
    • 2013-09-17
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    相关资源
    最近更新 更多