Reputation: 1460
I have a node application that I can start with node server.js
and access on localhost:9000.
I have a series of e2e tests on selenium that run fine, but I am now looking to use the docker selenium image.
I start the docker image with docker run -d -p 4444:4444 selenium/standalone-chrome
and I changed my e2e test code to look like:
var driver = new webdriver.Builder().
usingServer('http://127.0.0.1:4444/wd/hub').
withCapabilities(webdriver.Capabilities.chrome()).
build();
// driver.manage().window().setSize(1600, 1000);
return driver.get('http://127.0.0.1:9000')
.then(function() {
// driver.executeScript('localStorage.clear();')
return driver
});
But selenium fails to connect to the app at all!
(If I uncomment the setSize line, the program fails right there)
I have the server up an running, and it's indeed accessible at localhost:9000. How can I get my test to properly use dockerized selenium, and properly point to a server on localhost?
Upvotes: 3
Views: 3431
Reputation: 8449
Just to make sure I understand - the selenium runs in the docker, and tries to access the node app that runs on the server?
In this case, these are two different "servers", so you need to use real IP addresses (or dns names)
pass the ip of the server as a parameter to the dockerized selenium image the simplest thing would probably be as an environment variable
Upvotes: 0
Reputation: 16405
If you want your container network behaviour to be like your host machines use docker run --network=host
Upvotes: 1
Reputation: 943
What is docker ps command is returning for this container? Is it display like "0.0.0.0:4444->4444/tcp". ?
You can run sudo iptables -L -n and verify under "Chain DOCKER" section below line should come. ACCEPT tcp -- 0.0.0.0/0 x.x.x.x tcp dpt:4444
Upvotes: 0
Reputation: 799
If you are using mac, you may try to get gateway from netstat inside docker image:
netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}'
or write ifconfig
from terminal, and get the inet address, try with that instead of 127.0.0.1
.
Upvotes: 0
Reputation: 977
From the host machine, Docker endpoints aren't accessible at localhost. Did you try using 0.0.0.0
instead of 127.0.0.1
?
Upvotes: 0