title: Connect to SQL Server database from a docker container
body: <p>I have docker for windows installed on my machine. There is a console application targeting .net core 1.0.0 that tries to access a SQL Server database running on a different VM. I can ping the VM running SQL Server from my machine.</p>
  
  <p>When I try to run the console application using <code>dotnet run</code> from the command prompt on my machine it works fine. But when the same application is run inside a docker container I get a message </p>
  
  <blockquote>
    <p>A network-related or instance-specific error occurred while
    establishing a connection to SQL Server. The server was not found or
    was not accessible. Verify that the instance name is correct and that
    SQL Server is configured to allow remote connections. (provider: TCP
    Provider, error: 40 - Could not open a connection to SQL Server)</p>
  </blockquote>
  
  <p>I tried using </p>
  
  <pre><code>docker run --add-host sqldemo:&lt;VM running sql server ip here&gt;
  </code></pre>
  
  <p>but that made no difference.</p>