无法使用docker-compose.yml从Rails sidekiq连接到selenium-hub

时间:2018-06-15 14:07:50

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

尝试使用docker-compose从sidekiq worker运行selenium。 如果我从rails任务运行作业,它运行良好。但是当我从sidekiq运行时,它不起作用。 当我从sidekiq运行Job时,我收到了这个错误。

  

Errno :: EADDRNOTAVAIL:无法打开到localhost的TCP连接:4444(无法分配请求的地址 - connect(2)for“localhost”port 4444)

搬运工-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

请建议我如何解决此问题

1 个答案:

答案 0 :(得分: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