Search code examples
rubylinuxtcpdockerselenium-grid

Docker "Failed to open TCP connection to 127.0.0.1:4444" when running selenium/capybara test in container


I have some Selenium Webdriver/Capybara automation setup in a ruby app. Along with this in a VirtualBox VM using Linux I have a docker container for Selenium grid docker run -d -p 4444:4444 --name selenium-hub -e GRID_TIMEOUT=120000 selenium/hub:2.53.0 and a firefox node docker run -d --link selenium-hub:hub selenium/node-firefox:2.53.0. After adding a DNS entry to docker_opts on the VM, in my host machine if I run my Selenium test (which uses the grid on my VM) everything works fine. After this I setup my automation code in a ruby container on my vm along side the grid and containers. The container builds just fine. I am also able to attach to it without issue and all my code is there as expected. from the terminal in my automation container if attempt to run a spec ex. rspec spec/some_spec.rb I will get a connection refused error

"Failed to open TCP connection to 127.0.0.1:4444 (Connection refused - connect(2) for \"127.0.0.1\" port 4444)"

of the 18 results googling up this issue the only thing I saw that seemed actionable mentioned creating a bridge, which I don't really understand. Any suggestions on how to correct this would be greatly appreciated.


Solution

  • It's not easy to say without seeing your specs but I'm guessing you connect to selenium on 127.0.0.1:4444 in your tests?

    If so you should now connect to it on hub:4444 as that is the name which will resolve to the IP of your selenium hub container.