简体   繁体   中英

Can't connect to selenium-hub from Rails sidekiq with docker-compose.yml

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM