Communicate from service BACK to job container

Hello,

I’m trying to build some selenium tests that use a docker image to host chromedriver (specifically the selenium/standalone-chrome image). This uses port 4444 by default.

My job itself runs in a container and runs a simple web server on port 5000 as well as then running the selenium script.

So the network comms looks like this:

  job container -> SELENIUM COMMAND -> selenium service container
  selenium service container -> HTTP GET -> job container

 Which isn’t working as I don’t know what IP or hostname to use in the selenium command. Normally I’d use host networking mode in docker and just use localhost. Is there a way to get the IP or a hostname of the job container so that the service can communicate back?

Resurrecting this because I had exactly the same problem (and with chromedriver too).  Figure it will be handy to put in a solution

I found that this works to give the container a name (in this example, the hostname becomes “mainservice”).  You can then acess it using Docker networking.

container:
      image: ruby:2.6.5
      options: --network-alias mainservice

Do note that the Docker DNS resolution is case senstive (bonkers, I know!) so be careful with your name.