I am trying to connect to an sql server from my windows container. It all works fine when I spin up the container locally on my machine, or on an azure vm, and I can connect to the azure sql server but the connection fails when I deploy the container to azure container instance. The sql server firewall is open 0.0.0.0 to 255.255.255.255.

I believe that I have narrowed it down to a DNS issue because when I try to lookup the sql server or any host for that matter I get a "No such host is known". There is a known 30 second startup delay but it still does not resolve after multiple retries.

IPHostEntry ipHostInfo = Dns.GetHostEntry("mysqlserver.database.windows.net");  
IPAddress ipAddress = ipHostInfo.AddressList[0];  
Console.WriteLine($"Ipaddress {ipAddress.MapToIPv4()}");

1 Answers

1
Community On

Further to my original question I have come up with two options to resolve this issue.

  1. If you are working with a .netcore project then set build target to linux and deploy to a linux container/environment. The DNS lookup then works as it should.

  2. If you are stuck with a non .netcore project then run a powershell script on the container bootstrap to force the container to use a public DNS such as Google (8.8.8.8).

$nic = Get-NetAdapter
Set-DnsClientServerAddress -InterfaceIndex $nic.IfIndex -ServerAddresses ('8.8.8.8')