Specifying url in hosts file

I am using the selenium/standalone-chrome-debug docker image and I need to connect to my nginx container with a specified url from codeception. When I add the ip of the nginx container followed by my url “testing” into the hosts file of the selenium container, it works.

What is the best way to go about doing this. I have looked at extra_hosts but the IP can be dynamic.

I should also mention I am using docker-compose to load up the containers.

Also looked at running selenium on the host network so it can access the hosts etc/hosts file but that did not seem to work.

Thanks!

Not sure how to dynamically achieve this but I guess you could use docker-compose’s service links option to specify where a specific host in your selenium container should point to. This way, you won’t have to deal with IP addresses and the hosts file. Quick example below of a docker-compose.yml config

services:
    httpd:
        # options for web server container
    selenium:
        image: selenium/standalone-chrome
        links:
          - httpd:custom-host.local

Sorry for the late response on this… but this was the actual way I went about this.

Thanks for the reply!