Docker on Windows Connecting to sql server from dotnetcore app

I’ve built a simple api using asp.net core that returns some data from a sql server database.

It runs fine in VS and from the command line, but when i build and run the app as a docker container on my windows 10 machine when i call the api i keep getting this error

  • How to launch my docker container automatically on ECS?
  • Registering an ELB to an ECS service with random host port
  • REST API container create and port bindings
  • linkings several docker containers together
  • Nginx as Reverse Proxy for Docker VHosts
  • Docker run -d <private image> gives fatal. On other hosts it's ok?
  •  System.Data.SqlClient.SqlException: Connection Timeout Expired.  The timeout period elapsed during the post-login phase.  The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections.  The duration spent while attempting to connect to this server was - [Pre-Login] initialization=425; handshake=265; [Login] initialization=5; authentication=9; [Post-Login] complete=14034;  ---> System.ComponentModel.Win32Exception: Unknown error 258
    

    I’m not really sure what this is telling me, it’s as if it cant find the sql server machine. Do i have to expose port 1433 somehow in the docker config or when i run the container up?

  • What is the most simple setup for a MEAN stack docker container to have the same config on OS X and DigitalOcean?
  • Using docker on Mac. Is it possible to start docker daemon using docker-machine and pass in arguments?
  • Symfony2 app always has a 3 second wait between kernel.request and kernel.controller
  • How do I provide credentials to the docker awslogs driver using Docker for Mac?
  • Galera Cluster Rancher Node Scaling Issue
  • Can several nodes access mounted docker containers
  • One Solution collect form web for “Docker on Windows Connecting to sql server from dotnetcore app”

    As Tseng explained in his comment, your containers are in their own network, not in your host’s network. You’ll want indeed to expose that port (or map to another available port on your host), which you can easily do with Docker Compose. In the example below (that you’d but in a docker-compose.yml file), sql is the name of your database container, 1337 is the local port, and 1433 is the container’s port.

    sql:
     ports:
     - "1337:1433"
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.