Running Dockerized Webdriver Tests when Host Machine has no Internet Connection

0

In order to develop WebDriver Tests from my MacBook, I am using extra_hosts to create an entry in the Docker Container's /etc/hosts file to point the Chrome Browser inside the Docker Container to the Application running on the Host MacBook.

inside chrome.yml:

version: '2.1'
networks: {}
services:
  chrome:
    extra_hosts:
    - "test:${HOST_IP}"

HOST_IP gets set inside runner.sh:

export HOST_IP=VALUE_PARSED_FROM_IFCONFIG
docker-compose -f chrome.yml up -d --build chrome

By doing the above, the Application running on the Host MacBook is addressable at http://test from inside the Docker Container. This has been working properly for a while now.

However, when the Host MacBook is without Internet Connection (if I'm traveling, for instance), the above breaks down because HOST_IP is empty (i.e.: the ifconfig command I'm using does not return a valid IP Address).

I am aware that host.docker.internal provides an IP Address suitable for this purpose from within the Docker Container, but I don't know how to get this IP Address prior to running docker compose...

Dan Riley

Posted 2019-05-29T03:32:41.710

Reputation: 1

No answers