Docker Container Can't connect to remote SQL Server
Currently I have a Worker service that will interact with a sql server on a remote server. when it is deployed to my local machine, it works. But once I deploy it as a docker container, it fails the connection and printout this error
I have tried to search online from stackoverflow and in docker community, I have checked the firewall and tried different combinations compare to their post but it still did not work out...
27 Replies
R u using the localhost in the connection string?
No it is a remote sql server, have to connect it using the ip address
Okay is the ip correct from the container?
And r u using WSL for it?
Or via powershell?
Sorry I'm a beginner on Docker, what does that mean?
Like from where do u start ur container?
from my windows terminal, when I run the container I set the --network = host
and it is a linux container
Maybe this will help u: https://stackoverflow.com/questions/33001750/connect-to-mysql-in-a-docker-container-from-the-host
Stack Overflow
Connect to mysql in a docker container from the host
In a nutshell
I want to run mysql in a docker container and connect to it from my host. So far, the best I have achieved is:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '...
Let me have a check
Sorry just to double check if I didn't get it wrong, does that mean I need to firstly set up the connection from the container internal linux environment to be able to connect to the remote sql server or the remote ip address and then my program as a container can then be able to using EF core to interact with it?
u connect to the Linux environment with the ip address
And user name and pwd that u defined in the docker container
U don’t connect directly with the ms sql server in the container
U connect with the container direct
So in the connection string u need to define the ip from the Linux environment with the port
E.g. 111.111.111.111,1433
Sorry I didn't understand it, in my code the connection string is this "Data Source=xxx.xx.xxx.xx,1433;initial Catalog=xxxx;User ID=xxxx;Password=xxxxxx;MultipleActiveResultSets=true" but the Data Source should be another format that needs to be compatable in the container's internal linux environment?
Or does it mean I need to start up a sql server container that connects to the remote server and then connect my program onto this new sql server container...?
Medium
Executing a SQL Server Docker Container and connecting to a .Net
In this article, I will show you how to create a SQL Server docker container and how to use it in the .Net project with DDD created in…
i made a mistake im running my containers in linux subsystem thats why i need the ip from the enviroment
look at this guide
Hi, I have just checked this, but this exmaple seems trying to make a new container that connects to a local sql server rather than a remote one. My remote sql server is running in a windows server on another machine...
ohh okayyy
is the server in the same network?
Yes
u have a windos server and at that server u are running a docker container?
Sql server is on a windows server, docker is held on another windows11 machine but in the same network
Containers are Linux contianers
and why r u using the docker container?
what is the reason behind this setup
i need the details
Company's decision..
u can just connect direct to the windows server
the benefit for the docker is unclear for me
unless u want to run it on a diff os
But I'm getting error when I try to connect to the sql server from the container...
then the firewall blocks the connection
I think I have configured it already, otherwise the program I deployed locally shouldn't be able to connect to it..?
double check it
can u ping the ip from the windows server from ur container?
When I go into the terminal of the container I wasn't able to ping to the ip, but when I do it in on my docker host machine, it was all fine
thats how u get the ip from the docker container: https://stackoverflow.com/questions/17157721/how-to-get-a-docker-containers-ip-address-from-the-host
Stack Overflow
How to get a Docker container's IP address from the host
Is there a command I can run to get the container's IP address right from the host after a new container is created?
Basically, once Docker creates the container, I want to roll my own code deploy...
Maybe in your Windows11 you need to manually type your windows server host address
C:\Windows\System32\drivers\etc