title: How to connect to SQL Server docker container from another container?
body: <p>I have pulled and run SQL Server 2017 container image using the following command:</p>
  
  <pre><code>docker pull microsoft/mssql-server-linux
  docker run --name mssql -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=!Abcd123' -p 1433:1433 -d microsoft/mssql-server-linux
  </code></pre>
  
  <p>And I also deployed an ASP.NET Core Web API application to a Docker container, using the following commands:</p>
  
  <pre><code>dotnet publish -c Release -o Output
  docker build -t apitest .
  docker run -p 3000:80 --name apitest_1 apitest
  </code></pre>
  
  <p>The content of <code>Dockerfile</code>:</p>
  
  <pre><code>FROM microsoft/dotnet
  COPY Output /app
  WORKDIR /app
  EXPOSE 80/tcp
  ENTRYPOINT ["dotnet", "DockerSQLTest.dll"]
  </code></pre>
  
  <p>In my Web API application, I have created an Entity Framework Core migration which will create the database and seed some data. In <code>Configure</code> method of <code>Startup</code> class, I add the following code to apply the pending migrations to the database:</p>
  
  <pre><code>public async void Configure(IApplicationBuilder app,
                              IHostingEnvironment env, 
                              StudentDbContext dbContext)
  {
      await dbContext.Database.MigrateAsync();
      ...
  }
  </code></pre>
  
  <p>And the database connection string is retrieved from <code>appsettings.json</code> which contains the following section:</p>
  
  <pre><code>"ConnectionStrings": {
      "DefaultConnection": "Server=localhost,1433;Database=student;User Id=sa;Password=!Abcd123;"
  }
  </code></pre>
  
  <p>But the app cannot run correctly, the exception message:</p>
  
  <pre><code>fail: WebApplication6.Startup[0]
    System.Threading.Tasks.TaskCanceledException: A task was canceled.
       at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
       at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.&lt;&gt;c__DisplayClass20_0.&lt;&lt;ExistsAsync&gt;b__0&gt;d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.ExistsAsync(CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken)
  </code></pre>
  
  <p>Is there anything wrong?</p>