1
votes

Trying to run selenium from sidekiq worker with docker-compose. It works well if I run job from rails task. But It doesn't work when I run from sidekiq. I got this error when I run Job from sidekiq.

Errno::EADDRNOTAVAIL: Failed to open TCP connection to localhost:4444 (Cannot assign requested address - connect(2) for "localhost" port 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

Please suggest me how to fix this problem

1

1 Answers

2
votes

I have it working with a docker-compose.yml like this:

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