Selenium can't access main container




I’ve been trying to setup a CircleCI workflow using selenium/standalone-chrome

I define a name for the selenium container as below :

version: 2
    working_directory: /var/www/
      - image: talentify/php-apache
      - image: selenium/standalone-chrome
        name: selenium

Plus a custom host enabled.

After ssh’ing I can:
wget/curl with success
wget/curl selenium:444/wd/hub with success

However, when running the acceptance testes, selenium tries to access, or localhost, or, it fails saying that the host is unreachable.

How can I access the web-server running in my main image from the selenium docker image?


Your networking stack is all merged into localhost, I think, so I would try that. I’d also:

  • Add a sleep before kicking off the tests - if those containers are started in parallel, you have a race condition between them and whatever run steps you add below.
  • If that doesn’t work, consider a port >1024 - Linux can be funny with reserved ports. I tend to go for very high ports e.g. 8000, depending on what is free.


I know that this is not a race condition because I’m getting this issue even when I ssh and manually run the tests after everything is up and online.

I’ll test different ports


Did you try pinging the server by name? I am not sure, but I think accessing containers by name works inside containers, but not outside them. That may be your issue (and you may have a race condition as well, which perhaps is why it did not work via a post-fail SSH).



From the container I ssh into (the main image) I can ping:

  • localhost
  • (same container/ip as localhost)
  • selenium (another container)

According to the logs on the build page, everything is up and running about a minute before the tests start. I even used dockerize to make sure the DB and everyone else is okay before the tests are executed, but it still fails as “can’t connect to”


I managed to make both containers see each other by doing this:

hostname -I > /tmp/hosts #adds your main container IP to a tmp file
sed -i '/./s/$/' /tmp/hosts #adds your hostname to the tmp file
#copy tmp as a hosts file to the selenium container
sshpass -p "password" scp /tmp/hosts root@selenium:/etc/hosts


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.