-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to connect to SQL Server on host from docker #302
Comments
Um... Sorry, I just found a section of documentation I missed... I'll try that and reopen if it doesn't fix it... |
Ok, went through the docs and still getting the exact same message. |
So, somehow my container can't access 1433 on outbound connections, so I moved SQL to port 22 and it connects. |
@drewclauson: Is there a faster way i can get back to you on this problem? I want to setup my project to connect to Mssql too |
@chucky2305, @Hadis-Fard I actually figured it out using port 1433 and then forgot to post back here. I had to set the connection string to |
Can you share your dockerfile? i have no clue how to get my php running with extension etc for mssql. |
@chucky2305 Take a look here 😄 |
@drewclauson , @chucky2305 the suggestion here helped me solve the same issue i was experiencing.. in my case, specifying the here is how the conn'string look like: and then |
None of those suggestions are working. I get this error regardless of the application I am using or building: |
I had the same problem. I used a docker container to connect laravel to SQL server on mac, and it just didn't connect. the problem was, port 1433 of the container was NOT ported to localhost:1433, but to 0.0.0.0:1433. Changed the hostname to 0.0.0.0 and it worked. you can see the hostname by typing this: |
Im doing this on a Mac. Create a container for sql server to run in, assign a port (1433) and give it a name (sql1). $ docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>" create a container for your web app, in my case I'm using Visual Studio for Mac and added Docker Support to my projects, so docker-compose.yml actually creates the containers. I added the container_name in order to create named instance to add to a network, and it looks like this: version: '3' services: coresecuretest: api: Next I create a network: Example: docker network create [network name] $ docker network create simple-network Then I connect the containers to the network: Example: docker network connect [network name] [container name] $ docker network connect simple-network sql1 Then I inspect the network in order to get the ip of sql1 $ docker network inspect simple-network //// and use the IP (172.19.0.2) for my connection string, in my case its a sql connection using the port specified when I created sql1 container: "Server=172.19.0.2,1433;Database=My-Database;User=sa;Password=@Pa55word;" To ensure all containers are running: $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES In Sql Operations Studio (I'm using a Mac, Windows users SSMS) I use "localhost/sql1,1433" as server name to connect to this instance of Sql Server. Hope this helps. It took me a few hours to stumble upon the answers. |
@GrahamUndone - I'm having the exact same issue as you. Are you using Entity Framework? |
hello @GrahamUndone what did you do in this section? I didn't understand very clear. I'm using entity framework "I added the container_name in order to create named instance to add to a network, and it looks like this:" version: '3' services: coresecuretest: api: What did you do there? is the only step I have to finish because I still get the error in Visual Studio for Mac. I get this "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: 40 - Could not open a connection to SQL Server)" What Did I do?
when I run docker network inspect simple-network I can see the container with the IP as you said in the above comment, but when I try to connect from Visual Studio for Mac I can't. Some help? |
Using Docker to run sql server 2017 container image. Container image for sql server running successfully. I still get the following error when trying to create a connection in SQL ops studio 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: SQL Network Interfaces, error: 25 - Connection string is not valid) created container with the following cmd created network and linked network name with container name. |
I'm having the same issue I can't connect from my .NET core application inside my docker container to the SQL server. The SQL server is not running inside a docker container. It works fine when I run the .NET core application without docker, but somehow inside docker it behaves differently? I tried using the IP address, adding the port etc... nothing seems to work. Anyone who can help me out? |
After facing this problem, first thing I would do is ensure that connectivity is the real problem by setting the connection string 'internally' instead of trying to pass it to the container through an environment var. |
I did that. Connection string is hard coded as a string in my solution. This is not the problem. |
Here is my error:
|
@woeterman94 We have had a similar issue https://github.com/dotnet/corefx/issues/9719 at the .NET Corefx Repo. As per comments from the users the issue was resolved after updating to https://github.com/dotnet/corefx/issues/9719#issuecomment-233425704
https://github.com/dotnet/corefx/issues/9719#issuecomment-277327056
https://github.com/dotnet/corefx/issues/9719#issuecomment-356674773
Since, I am not sure what version of SQL Server you are using, could you try the versions mentioned above or any SQLServer version later than the ones mentioned above and revert back. |
actually Ipaddress helped but after i removed tcp port 1433 , it worked , For those facing this issue |
|
I had a similar issue. solved it by checking my windows host file and found an internal docker IP Used this ip to connect using the port i had defined (1432) and was able to connect without any further issues. Hope this helps. |
I am having issue where i am not able to connect to ssms which is in host machine from asp.net core application running in docker container. My connection string is Server=,;Database=Demodb;Integrated Security=True; I am getting error as server not found. any help will be appreciated. |
Is your server by name ','(comma) ? Did you mean '.'(dot) ? |
This is my connection string Server=ipaddres,port;Database=Demodb;Integrated Security=True; |
Use full domain name space and followed by instance name . |
Managed to get it working with the following to workaround: I had SQL Server running on windows with a linux container on the same machine trying to connect. I tried quite a lot of things suggested here and stack overflow but had no luck. The error I was getting was a bit different to the others: I could ping my machine name from a container so I knew that was not the issue. Looking at the error more closely it looked like something to do with TCP, so I white listed TCP/UDP on ports 1433,1434. Which still didn't work. I then checked to see if remote connections were enabled on the database and it was already enabled. I then checked Sql Server Configuration Manager -> Sql Server Network Configuration -> Protocols for MSSQLSERVER -> TCP/IP and it was disabled. I enabled it and tried again and it worked. So I didn't need to add the port with a comma or use ip address... Hope this helps someone. |
Let me share my experience as well - I had the same issue. How I resolved it:
|
thank you |
Rather than use IP addresses, which would be problematic in a team environment, you can also use
|
I've ran into a similar problem as few have in this thread. Google took me here repeatedly so, I'll comment my problem here. I am getting the error mentioned in this thread from a container running a service attempting to connect to SQL. And I am also getting this error when running bash in the container running SQL and attempting to connect via sqlcmd. sudo docker exec -it <mssql container> "bash" # allows me "remote" into container
$
/opt/mssql-tools/bin/sqlcmd -S <IP>-U SA -P "<YourNewStrong@Passw0rd>" # lets connect The above test does work when specifying localhost. It does not work when attempting to connect via the host IP.
Exploring with TelnetIn an attempt to narrow down the problem. I began running telnet from within the container and the host.
From the host
IPTABLESAn investigation into the rules docker setup on the iptables, I found the following -A DOCKER -d 172.17.0.2/32 ! -i docker0 -o docker0 -p tcp -m tcp --dport 1433 -j ACCEPT
# [! -i docker0]
# this sections says allow connections coming from network interfaces that are not docker0 These rules are implementation details managed by Docker, so perhaps I have faulty configuration on my containers (e.g. relying on the default bridge on the docker network) I'm not confident this is a smoking gun in anyway. But hopefully, someone more familiar with the subject matter can rule this out or further identify the problem. |
My problem is due to an VPN, ulse Connect MX, it works after close the VPN. |
As keeratsingh mentioned: try upgrading your SQL server version, as this is most likely a TLS version problem. |
As reference to my prior comment, the issue for me was a misunderstanding of docker networks. The default bridged network created a rule that did not allow docker instances to access the forwarded 1433 port. In order to get my docker instances talking to each other, I had to use the docker bridge network IP associated with the containers. The port forwarding done for 1433 to the docker network did work as I expected. |
Was able to reproduce using the following .NET Core 3.1 app running on the
The program hanged on the Absolutly no issue for anything 2016 and above. |
Your issue relates to a known issue: dotnet/SqlClient#201. Please ensure you update SQL Server to support TLS 1.2 as docker clients do that by default now, in order to work. Watch the issue for more user experiences and how they resolved this problem. |
This helped me, for me it was 192.168.0.108 |
I had a similar problem with sqlcmd, trying to connect to sqlserver running inside a container in docker-machine on macOS. The solution was to use the IP address of docker-machine's default instance (192.168.99.100), not localhost as I'd initially assumed. Just thought I'd mention it here for those who find this issue via a search engine. Details:
|
I'm trying to connect to an SQL Server that is also inside another Docker container. In my case, I put together the comments of @Kriti86 and @GrahamUndone and it worked! I configured a simple network for docker and checked my SQL server container IP. Then, I used that IP as the value for SERVER. It is important to say that I did not use any port number, just the IP address. |
For me it worked by setting the network mode to bridge |
Not necessarily directly related but.... I couldn't get the So in summary, I had to;
|
Thanks alot. I've been stuck on this problem from quite some days. Tysm |
@aeslinger0 |
was struggling with this for hours, for me just changing localhost to 127.0.0.1 fixed it! |
save my day man! |
In the entire internet, after hours of googling, this is the only answer that worked |
@drewclauson Connection id "0HML6LRK6J7BB", Request id "0HML6LRK6J7BB:00000001": An unhandled exception was thrown by the application. As it is saying connection string is not valid please find below the connection string given in my code "ConnectionStrings": { tried other ways but still showing same error Am using Ubunut 20.04 which hosted in different cloud apart from AWS cloud so my AWS RDS MSSQL is not in same VPC Can you please help me out @drewclauson or anyone else can help will be helpful.. Thanks... |
Pls can you help me out with this via rdp? |
I've got a docker container running that I'm unable to access an external SQL Server from. I'm using sqlsrv-4.1.6.1, PHP 7.1.
When trying to connect via PHP, the error message returns as:
A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
I am able to connect to the SQL server on the docker host machine from the host and also from another windows machine via SSMS. The docker host machine is Windows 10 64bit.
When I try to telnet from the container to the host IP address, I get:
Trying 10.20.86.176... telnet: Unable to connect to remote host: Connection refused
Using telnet to get to ports like 80 or 22 are successful, since both ports are open and working on the docker host.
Any ideas? Can post my DockerFile if that's helpful
The text was updated successfully, but these errors were encountered: