Selenium can't access main container

selenium

#1

Hi,

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
jobs:
  build:
    working_directory: /var/www/
    docker:
      - image: talentify/php-apache
      - image: selenium/standalone-chrome
        name: selenium

Plus a custom host dev.host enabled.

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

However, when running the acceptance testes, selenium tries to access dev.host, or localhost, or 127.0.0.1, 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?


#2

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.

#3

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


#4

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).


#5

Yes.

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

  • localhost
  • dev.host (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 dev.host”


#6

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/$/ my.host.name/' /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


#7

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