Search code examples
dockerseleniumselenium-webdrivercodeception

Allowing docker container to access localhost


I am trying to run selenium docker image

docker run -d -p 4444:4444 --shm-size 2g selenium/standalone-chrome:4.0.0-beta-3-prerelease-20210329

from this image: https://hub.docker.com/r/selenium/standalone-chrome

When I run this command, I can see Selenium on http://localhost:4444/

What I need is to allow selenium to access my localhost URL. I was looking through documentation but I was unable find anything that mentions it.

I am using Selenium to trigger Codeception tests and I saw here mentioning about docker container for Selenium (https://codeception.com/docs/modules/WebDriver#headless-selenium-in-docker), but that command actually starts Selenium, but I am not sure how to access it. This is the command and the log:

docker run --net=host selenium/standalone-chrome

2021-03-30 10:33:15,835 INFO Included extra file "/etc/supervisor/conf.d/selenium.conf" during parsing
2021-03-30 10:33:15,839 INFO supervisord started with pid 9
2021-03-30 10:33:16,848 INFO spawned: 'xvfb' with pid 11
2021-03-30 10:33:16,854 INFO spawned: 'selenium-standalone' with pid 12
10:33:17.160 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
2021-03-30 10:33:17,161 INFO success: xvfb entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2021-03-30 10:33:17,162 INFO success: selenium-standalone entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
10:33:17.261 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2021-03-30 10:33:17.318:INFO::main: Logging initialized @435ms to org.seleniumhq.jetty9.util.log.StdErrLog
10:33:17.577 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
10:33:17.680 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444

Any help to get either of these two ways working.


Solution

  • docker run -d -p 4444:4444 selenium/standalone-chrome -p flag will allow access from localhost, tested on windows