I've tested a docker compose locally where I have a selenium/standalone-chrome container and a dotnet core one with automated UI tests implemented. Using hostname setting in the docker compose file, I can proper connect and run the automated tests with success.
Now I'm trying to deploy them to Azure Web App for Container, but the dotnet core application is raising an error saying it could not connect to the other container:
2022-04-29T19:22:26.175504823Z Unhandled exception. OpenQA.Selenium.WebDriverException: An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL http://chrome:4444/wd/hub/session. The exception message was: Name or service not known
2022-04-29T19:22:26.175552225Z ---> System.Net.Http.HttpRequestException: Name or service not known
2022-04-29T19:22:26.175558125Z ---> System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known
2022-04-29T19:22:26.175562626Z at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
2022-04-29T19:22:26.175566926Z --- End of inner exception stack trace ---
2022-04-29T19:22:26.175571026Z at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
2022-04-29T19:22:26.175575226Z at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
2022-04-29T19:22:26.175579526Z at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2022-04-29T19:22:26.175583826Z at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2022-04-29T19:22:26.175588027Z at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
2022-04-29T19:22:26.175592327Z at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2022-04-29T19:22:26.175596627Z at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
2022-04-29T19:22:26.175601027Z at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
2022-04-29T19:22:26.175605227Z at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
2022-04-29T19:22:26.175615128Z --- End of inner exception stack trace ---
2022-04-29T19:22:26.175619328Z at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
2022-04-29T19:22:26.175623528Z at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
2022-04-29T19:22:26.175639629Z at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
2022-04-29T19:22:26.175643929Z at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
2022-04-29T19:22:26.175648529Z at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
2022-04-29T19:22:26.175652229Z at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)
2022-04-29T19:22:26.175656029Z at SparefootScrape.Program.StartDriver() in /src/Program.cs:line 99
2022-04-29T19:22:26.175659630Z at SparefootScrape.Program.Main(String[] args) in /src/Program.cs:line 39
2022-04-29T19:22:26.176521765Z at SparefootScrape.Program.<Main>(String[] args)
I also tried localhost rather than the 'chrome' value I've assigned using hostname in the docker compose file but it also didn't work.
Any tips?
Here's my docker-compose:
version: "1.0"
services:
scrape:
image: "xxxxxx.azurecr.io/yyyyy:4.0"
stdin_open: true # docker run -i
tty: true # docker run -t
shm_size: '2gb'
restart: always
depends_on:
- chrome
selenium:
image: "selenium/standalone-chrome:latest"
container_name: "chrome"
hostname: chrome
shm_size: '2gb'
restart: always
ports:
- "4444:4444"
I put it to work inverting the definition on docker-compose.yml and renaming the service: