I'm developing tests with Selenium. Currently I'm using official selenium/standalone-chrome:3.11.0 image. I'm running only Selenium inside Docker-container. The project itself is compiled on the host machine (tests connect to the container's exposed port):
$ docker run -p 4444:4444 selenium/standalone-chrome:3.11.0 $ curl -v localhost:4444 * Rebuilt URL to: localhost:4444/ * Trying 127.0.0.1... * Connected to localhost (127.0.0.1) port 4444 (#0) > GET / HTTP/1.1 > Host: localhost:4444 > User-Agent: curl/7.47.0 > Accept: */* > < HTTP/1.1 200 OK ...
But I would like to compile and test the project entirely inside Docker-container. So I created my own image upon
selenium/standalone-chrome:3.11.0. My (simplified) Dockerfile looks like this:
FROM selenium/standalone-chrome:3.11.0 RUN sudo apt-get --assume-yes --quiet update RUN sudo apt-get --assume-yes --quiet install curl CMD ["curl", "-v", "localhost:4444"]
As can be seen from the file, I'm trying to connect to port 4444 within container. When I run the image, e.g.:
docker build -t test . && docker run test
* Rebuilt URL to: localhost:4444/ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 127.0.0.1... * connect to 127.0.0.1 port 4444 failed: Connection refused * Trying ::1... * Immediate connect fail for ::1: Cannot assign requested address * Trying ::1... * Immediate connect fail for ::1: Cannot assign requested address * Failed to connect to localhost port 4444: Connection refused * Closing connection 0 curl: (7) Failed to connect to localhost port 4444: Connection refused
Why I'm not able to connect to Selenium which is ran inside container from the same container?