Unable to run Springboot app using Selenium RemoteWebDriver with docker-compose Unable to run Springboot app using Selenium RemoteWebDriver with docker-compose selenium selenium

Unable to run Springboot app using Selenium RemoteWebDriver with docker-compose


Problem

This http://localhost:4444/wd/hub URL refers to the localhost which belongs to the container runtime. The springboot container does not have port 4444 running that's why it's complaining.

Solution

You should access the selenium service from its hostname (not localhost). In springboot application, you can use, http://firefox:4444/wd/hub URL and you'd be good to go.

Rationale

You are missing the core of the networking concept in containers here. Both of these images (viz springboot and selenium) are running inside containers and hence they have their separate environments. If you refer to localhost inside any container, it means the localhost of that container. You are expecting localhost to refer to the localhost of the docker host machine. You exposed port 4444 on the docker host machine. So if you try to run your jar from the docker host (while selenium is containerized) localhost:4444 would work but if you access it from inside a container, it's not going to work. Following Diagram shows the concept:

docker network