Docker can not access external database server

I have an core that connects to a SQL Server. When I run it in docker on my local computer everything works as expected, but when run the docker image on a linux server (centos 8) i get a network error when trying to connect to the database. I don’t know what to do, since I used the actual server’s ip in the connection string and it still does not work.
Thank you a lot

Source: StackOverflow