title: Cannot assign requested address (localhost:4444)
body: <p>I have problem with <code>Selenium</code> when I want to create a Image in Docker. In fact, I developed a <code>.Net Core Api</code> using <code>Selenium Chrome driver</code> and I need to create its <code>Docker container</code> to deploy it on a server. The interesting point is that it works properly locally, but I face an error when I create its Image and try to run it. <br>It could but helpful to share my code.<br></p>
  <p>It is a piece of code in which I instansiate <code>chrome driver</code> :<br></p>
  <pre class="lang-cs prettyprint-override"><code>   ChromeOptions options = new ChromeOptions();
     options.AddArgument(&quot;no-sandbox&quot;);
     options.AddArgument(&quot;headless&quot;);
     driver = new RemoteWebDriver(new Uri(&quot;http://localhost:4444/wd/hub&quot;), options);
  </code></pre>
  <p><strong>Dockerfile</strong></p>
  <pre><code> FROM selenium/standalone-chrome:latest AS base
   WORKDIR /app
  
   # build and copy dotnet project
   FROM mcr.microsoft.com/dotnet/aspnet:5.0
   COPY bin/Release/net5.0/publish/ app/
   WORKDIR /app
   ENTRYPOINT [&quot;dotnet&quot;, &quot;Pand.dll&quot;]
  </code></pre>
  <p><strong>Docker Compose</strong></p>
  <pre><code>version: &quot;3&quot;
  services:
    selenium-hub:
      image: selenium/hub:3.141.59-yttrium
      container_name: selenium-hub
      ports:
        - &quot;4444:4444&quot;
      expose: 
        - 4444
    chrome:
      image: selenium/standalone-chrome
      container_name: chrome
      deploy:
        replicas: 5
      ports:
        - &quot;5900:5900&quot;
      volumes:
        - /dev/shm:/dev/shm
      depends_on:
        - selenium-hub
      environment:
        - HUB_HOST=selenium-hub
        - HUB_PORT=4444
          #Api  Service
    api:
      build:
        context: .
        #Use the DockerFile in that Directory
        dockerfile: Dockerfile
      environment: 
        - ASPNETCORE_ENVIRONMENT=Development
  </code></pre>
  <p>And this is an error after I use <code>docker run -p 8080:80 pand/backend</code> command:</p>
  <pre><code>crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
        Application startup exception
        OpenQA.Selenium.WebDriverException: An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL http://localhost:4444/wd/hub/session. The exception message was: Cannot assign requested address (localhost:4444)
         ---&gt; System.Net.Http.HttpRequestException: Cannot assign requested address (localhost:4444)
         ---&gt; System.Net.Sockets.SocketException (99): Cannot assign requested address
           at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
           at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
           at System.Net.Sockets.Socket.&lt;ConnectAsync&gt;g__WaitForConnectWithCancellation|283_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
  </code></pre>