Skip to content

Instantly share code, notes, and snippets.

@jkup
Last active February 5, 2018 20:46
Show Gist options
  • Save jkup/ce1bc58bd2a0371bda5f26ea35ba3ce1 to your computer and use it in GitHub Desktop.
Save jkup/ce1bc58bd2a0371bda5f26ea35ba3ce1 to your computer and use it in GitHub Desktop.
Docker Question

My Setup:

  1. I have a Node app running locally with Express + React + etc.
  2. I have an /etc/hosts entry mapping 127.0.0.1 to a necessary hostname 127.0.0.1 really.important.mycompany.com
  3. I have a standalone Docker image running selenium with standalone Chrome (https://hub.docker.com/r/selenium/standalone-chrome/)
  4. I have a webdriverio (http://webdriver.io/) suite of tests that need to run against the really.important.mycompany.com local hostname.

My process:

  1. I start the Docker image with: docker run --name mycompany-selenium --add-host -d --rm -p 4444:4444 selenium/standalone-chrome
  2. I start the local Node app with webpack-dev-server --hot --config webpack.dev.js
  3. I try to run the webdriverio suite with ./node_modules/.bin/wdio wdio.conf.js --baseUrl https://really.important.mycompany.com

My problem:

The selenium server doesn't seem to be able to hit the /etc/host entry on my host computer. Is there an easy way to do this?

What I've tried:

  1. Using docker.for.mac.localhost instead of the really.important.mycompany.com but like I said the hostname is vital for our app to run.
  2. A bunch of different stuff with the docker run command like --add-host localhost.adobecc.com:10.0.2.2 but it doesn't seem to help.
@nathanleclaire
Copy link

nathanleclaire commented Feb 5, 2018

Yeah this works for me.

In one terminal:

$ python -m SimpleHTTPServer 9090
Listening on 9090...

The container magic:

$ docker run -ti --add-host magic.domain.com:192.168.65.2 alpine sh
/ # wget -qO- magic.domain.com:9090
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html>
.... etc ....

How did I get 192.168.65.2? nslookup

$ docker run -ti alpine nslookup docker.for.mac.localhost
nslookup: can't resolve '(null)': Name does not resolve

Name:      docker.for.mac.localhost
Address 1: 192.168.65.2

Now, the caveat is that this IP might change, but it's a start.

@jkup
Copy link
Author

jkup commented Feb 5, 2018

Thank you thank you thank you! This worked perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment