Unable to connect to AWS RDS instance from docker container - docker

On my Windows 10 host machine I am able to connect to a private SQL Server RDS instance running in AWS. However, a Docker container running locally on the same machine is unable to connect with the same connection string.
From the Docker container I am able to telnet to the server on 1433 successfully. However, when I connect from code, it seems to be unable to create a connection. No exception is thrown, but this code hangs:
using (var conn = new SqlConnection(connectionString)){
// Do something
}
I am able to successfully connect to SQL Server when it is running on a EC2 instance. It appears to be specific to RDS.
Fails with both the name and IP address.

This was caused by a bug in SQLClient as described on GitHub. There were two fixes that worked:
Downgrade the project from Net Core 3.1 to 2.2
Update Docker file to use aspnet:3.1-bionic instead of aspnet:3.1-buster-slim and sdk:3.1-bionic instead of sdk:3.1-buster

Related

Connect ASP.NET Core container to remote SQL Server

I am trying to connect my ASP.NET Core application to a remote SQL Server.
The application is deployed using IIS WScore 2016 image. When I run the application on my host, it's working, but in the container using this connection string :
Data Source=xx.xxx.xx.xx,1433;Initial Catalog=somedb;User Id=xxxxxx;Password=xxxxx;
or:
Server=xx.xx.xx.xx,PORT_NB;Database=DATABASE;User Id=USER;Password=PASSWORD
But no luck - I am using the default Docker network.
The error is like this:
Error: 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: 0 - No such host is known.)
Notes:
The server is allowing the remote connection
All the connection strings are tested and can connect to the remote SQL Server from the application that runs on the host
I have read the Docker documentation and they mentioned the IP forwarding but the example was on linux containers and I did not find any help about connecting the Windows containers to a remote SQL Server
Question
My concrete question is how to expose the container to the outside world and I can connection my container to the other remote services like a remote SQL Server?
Should I use host network or bridge with the IP forwarding?
Any help? Thanks
I changed the connection string to this :
"ConnectionString": "Server=xx.xxx.xx.xx\\MSSQLSERVER,1433;Initial Catalog=Dbname;User Id=username;Password=xxxxxxx;"
then i restarted the AppPoll and it worked
What is the current network you're using for this container? If you used the default network, then you're using Network Address Translation (NAT). What that means is that you're using the host IP address to connect to the external network. So, your problem most likely is that the SQL Server is rejecting the connection from the IP of the container host.
The alternative on Windows is to use a different network drive. There are many options and I'd recommend you look at the option that better suits your needs: https://cda.ms/4nP
I had the same error, try removing the port from the connection string as follows:
"ConnectionString": "Server=ContainerName;Initial Catalog=Dbname;User Id=username;Password=xxxxxxx;"

Unable to connect Azure Database from Kubernetes cluster using Kubeadm

I have a MVC application which is using Azure SQL database for data storage. I have created a docker image for the same.
Later, I have setup Kubernetes cluster on Ubuntu 18.4 using Kubeadm. The Linux VM is is created on azure cloud.
Initially, i have deployed my app on the single node cluster and the application was working as expected without any SQL connection issue. Then I have created two VM on the cloud and used it as Node 1 (master) and Node 2. Now i am facing an SQL connection issue after deploying my app on Node 2 machine.
Unhandled Exception: System.Data.SqlClient.SqlException: 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: 35 - An internal exception was caught) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: Resource temporarily unavailable
I tried and verified below options-
Added IPs to Azure SQL database firewall settings
From Linux Machine, tried to connect SQL database using sqlcmd
POD network is install correctly (calico)
Tried adding outbound rule for SQL port 1433 on VM
I have created a SQL database on VM and tried to connect this database from MVC app and it is also working.
Can someone please help me to diagnose and fix this issue? Please let me know if you want more details on this.

ECONNREFUSED 127.0.0.1:80 when connecting to remote Docker with Visual Studio Code

I want to develop code inside a container on a remote Docker host with VS Code, but I cannot connect to Docker on the remote machine via SSH (ECONNREFUSED 127.0.0.1:80).
Following the VS Code instructions to use a SSH tunnel (https://code.visualstudio.com/docs/remote/containers-advanced#_option-2-connect-using-an-ssh-tunnel) I got this error:
"Unable to connect to Docker. Please make sure you have installed
Docker and that it is running. Details: connect ECONNREFUSED
127.0.0.1:80"
I started VS Code (Windows 10), updated the docker.host (File->Preferences) property to:
{
"docker.host":"tcp://localhost:23750"
}
and ran:
ssh -NL localhost:23750:/var/run/docker.sock user#hostname
It looked like established the tunnel successfully. I run Docker on a virtual machine (centOS).
When I opened the Docker view and expanded the Containers node in the explorer I got the above mentioned error. To me it looks like VS Code tries to connect to port 80 but I specified port 23750 in the settings. How can I successfully connect to the remote host?
I found a fix here: https://github.com/microsoft/vscode-docker/issues/580
Remove the prefix tcp:// from the docker.host settings, e.g.:
"docker.host": "localhost:23750"
I know that this question is old but for anyone still looking for options I solved a similar issue on my computer using IPv6.
So in your case:
{
"docker.host":"tcp://[::1]:23750"
}
I configured the host on the environment variable DOCKER_HOST.

Unable to do DNS lookup in azure container instance - windows container

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()}");
Further to my original question I have come up with two options to resolve this issue.
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.
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')

Can't connect to a firebird server on docker

I'm a macOS user and I got weird errors just to create a database with firebird. I saw that there are some dock containers with firebird that run just fine ( i was able to create databases, perform queries and so on) but when I tried to connect from my local ISQL or razorSQL client ( through JDBC), I get some weird errors like "unavailable database" or "can't open file"
I'm also not sure how ISQL CONNECT string really works because every site I saw there is a different one.
I got this docker image: ( https://hub.docker.com/r/jacobalberty/firebird/)
I created my container like this:
docker run -d --name firebird -p 3050:3050 -v /data/firebird/databases:/databases jacobalberty/firebird:2.5-ss
my docker-machine IP is:
192.168.99.100
I tried to connect like this:
CONNECT '0.0.0.0:3050://databases/test.fdb' user 'SYSDBA' password 'masterkey';
unavailable database
And also like this:
CONNECT '192.168.99.100:/databases/test.fdb' user 'SYSDBA' password 'masterkey';
connection rejected by remote interface
CONNECT '192.168.99.100:3050:/databases/test.fdb' user 'SYSDBA' password 'masterkey';
Statement failed, SQLSTATE = 08001
unavailable database
When i enter the docker container, the file is there:
root#e4212b9f9d16:/databases# pwd
/databases
root#e4212b9f9d16:/databases# ls
test.fdb
Also, I'm not sure how to check if the firebird server is running ( i guess it is cause I can 'connect' to a database inside the container'.. but the docker container is definally up and running - did a successful telnet on the ip and port)
I also tried to use the container IP (172.17.0.2) but i got a timeout
Im most familiar with mysql and SQLite never touched a firebird db before and as the user got this DB, i have to mock it, develop an app using fake data and then connect it to the real firebird (so changing the DB is not an option)
So, the standard documentation about 'create your firebird server' don't mention but you on firebird.conf, the variable RemoteBindAddress must be empty
File:
/etc/firebird/2.5/firebird.conf
Lines changed:
RemoteBindAddress =
#RemoteBindAddress = localhost
Thanks for all the
Most of your problems are your connection string, it should be <host>/<port>:<database-path-or-alias>, where leaving of /<port> will default to port 3050.
This accounts for all your problems except for
CONNECT '192.168.99.100:/databases/test.fdb' user 'SYSDBA' password 'masterkey';
connection rejected by remote interface
As that connection string is a valid one.
This error means that you were able to connect to the server, but the connection was rejected. This might - for example - happen when you use Firebird 3, but connect using a Firebird 2.5 ISQL/fbclient library, and haven't relaxed the security settings of Firebird 3 (see Legacy Authentication in the Firebird 3 release notes).
In order to find out if the server is running, use:
docker ps
In order to figure out if the server actually started, or errored out upon start, start the container without the -d and look at the log messages when it runs:
docker run --name firebird -p 3050:3050 -v /data/firebird/databases:/databases jacobalberty/firebird:2.5-ss

Resources