title: Use VS Code (mssql extension) to connect to SQL Server running in Docker on Windows
body: <p>I'm using Docker on Windows, and I have a Docker container with SQL Server running. To start my container, I used the information shown <a href="https://hub.docker.com/_/microsoft-mssql-server" rel="nofollow noreferrer">here</a>:</p>
  <pre><code>docker run -e &quot;ACCEPT_EULA=Y&quot; -e &quot;SA_PASSWORD=yourStrong(!)Password&quot; -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-CU8-ubuntu
  </code></pre>
  <p>(Note, I'm using double qutes (<code>&quot;</code>) instead of single quotes (<code>'</code>) as I'm running on Windows.)</p>
  <p>My container is running and I can connect to it and query using <code>sqlcmd</code>:</p>
  <pre><code>docker exec -it &lt;container_id|container_name&gt; /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P &lt;your_password&gt;
  </code></pre>
  <p>(Note, I'm specifying the container ID found with <code>docker container ls</code>, and the password used when running the container, <code>yourStrong(!)Password</code>.)</p>
  <pre><code>1&gt; USE master
  2&gt; GO
  Changed database context to 'master'.
  1&gt; SELECT name, database_id, create_date FROM sys.databases;
  2&gt; GO
  name                                                                                                                             database_id create_date
  ----------------------------------------
  master         1 2003-04-08 09:13:36.390
  tempdb         2 2020-04-06 12:00:33.493
  model          3 2003-04-08 09:13:36.390
  msdb           4 2018-06-13 18:27:29.220
  </code></pre>
  <p>However, I want to use VS Code to connect to my SQL server instance, so after installing the SQL <a href="https://marketplace.visualstudio.com/items?itemName=ms-mssql.mssql" rel="nofollow noreferrer">SQL Server (mssql)</a>, I have tried to set up a connection, but it fails to connect.</p>
  <p><strong>Server Name</strong></p>
  <p><a href="https://i.stack.imgur.com/l095B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l095B.png" alt="enter image description here" /></a></p>
  <p>For the server name, I am using the IP address for the container, which is <code>172.17.0.2</code>. This is obtained using the <a href="https://stackoverflow.com/a/20686101/6236042">answer shown here</a>.</p>
  <p><strong>Database Name</strong></p>
  <p><a href="https://i.stack.imgur.com/zGn26.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zGn26.png" alt="enter image description here" /></a></p>
  <p>For the database name, I'm using <code>master</code>.</p>
  <p><strong>Username</strong></p>
  <p><a href="https://i.stack.imgur.com/j1e0S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j1e0S.png" alt="enter image description here" /></a></p>
  <p>For the username, I'm using <code>SA</code> (note that I've tried with both upper and lower case).</p>
  <p><strong>Password</strong></p>
  <p><a href="https://i.stack.imgur.com/1EtKe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1EtKe.png" alt="enter image description here" /></a></p>
  <p>I'm using the same password specified when running the container, <code>yourStrong(!)Password</code></p>
  <p>The last two steps are to &quot;Save Password&quot;, for which I select &quot;Yes&quot;, and to name the connection, for which I've tried specifying a name, and tried omitting it.</p>
  <p>The connection fails every time, and I'm not sure what the problem is. The credentials are definitely correct (unless they are somehow transformed when added into the prompts in VS Code, which is unlikely), the server name (IP) is correct, and the database exists.</p>
  <p>Does anyone know what the problem might be, or how I can troubleshoot this further?</p>
  <p>I know this <em>should</em> work, as I have successfully done the exact same thing on Linux. I am guessing this has something to do with Docker running on Windows, but cant be sure.</p>
  <p>Any help appreciated!</p>
  <h3>Edit</h3>
  <p>The error information when trying to connect:
  <a href="https://i.stack.imgur.com/gRjM3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gRjM3.png" alt="enter image description here" /></a></p>