4

A browser running in docker container needs to make a POST to a login service running on a test API in our network. The service is very picky about where POST can come from so it's rejecting the POST because it's coming from host.docker.internal instead of localhost.company.com.

It's very unlikely I'd be able to get host.docker.internal added to the whitelist.

The POST will work fine if the browser is running on my local machine but fails when the browser is running inside a container on my local machine.

I've tried docker run --add-host='localhost.mycompany.com:127.0.0.1' and docker run --add-host='localhost:127.0.0.1', neither one worked. The latter seems silly; it was kind of a shot in the dark...

A possible further complication: the browser is running in testcafe inside a Docker container, so my request will have headers like 'Origin: http://172.17.0.2:1337' 'Referer: http://172.17.0.2:1337/WBrtZV38p/http://host.docker.internal:3000/app/'

Short of making a proxy of some sort on my local machine, is there a way to make a POST from the docker container appear to be coming from my local machine?

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
jcollum
  • 43,623
  • 55
  • 191
  • 321
  • thers an extension for some browsers that removes the origin header (or stops it from adding it) this might work if its only for testing purposes – jonathan Heindl Apr 05 '19 at 19:39
  • Ive found this one even tohugh I havent used it personally which should do the trick : https://chrome.google.com/webstore/detail/requestly-redirect-url-mo/mdnleldcmiljblolnjhpnblkcekpdkpa – jonathan Heindl Apr 05 '19 at 19:40

1 Answers1

4

Start container in the host OS network space with docker run --network host ... - container will be running in the network of your local machine directly. But you will lose container network isolation, so you should to review security of this approach.

Doc: https://docs.docker.com/network/host/

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
  • Hmm, that might work but it seems to break my debugging ports `docker run --network='host' --expose 9230 -p 9230:9230 --expose 9222 -p 9222:9222 -e NODE_OPTIONS="--inspect=0.0.0.0:9230"` -- do you know how to work around that? It didn't fix my test so I need to debug and figure out what the headers look like – jcollum Apr 05 '19 at 20:12
  • Don't publish (expose) any ports - you are already running in host OS network. – Jan Garaj Apr 05 '19 at 20:14
  • Right but the test is still failing and I need to debug the browser that's running in the host to sort out what's happening. Chromium allows that with `--remote-debugging-address=0.0.0.0 --remote-debugging-port=9222` but if I can't expose those ports... I thought the node process would show up normally (as in, just like any other node process in debug mode) but it is not – jcollum Apr 05 '19 at 20:24
  • Publishing of the container ports = forwarding ports from the container network space to the host os network space. But with `--network host` you are already starting container in host OS network space and app are binding host OS network interfaces. So debug on your local host OS interfaces. – Jan Garaj Apr 05 '19 at 21:03