What would prevent the code running in the Docker container from connecting to the database on a separate server?

I have a .NET Core 1.1 application running in a Docker container on Ubuntu 14.04 and it cannot connect to the SQL Server database running on a separate server.

Error:

Unhandled exception: System.Data.SqlClient.SqlException: A network-related or specific instance error occurred while establishing a connection to SQL Server. The server was not found or was not available. Verify the instance name is correct and configure SQL Server to connect remotely. (provider: TCP provider, error: 25 - connection string is invalid)

  • I deployed the same image with the same command line on another Ubuntu 14.04 server and connected perfectly.
  • A console application running on a problem server (outside of Docker) can connect to the same connection string.

As far as I can see from the documentation, the application running in the container has access to the external network by default, so this connection can be blocked?

+2
source share
2 answers

the application running in the container has access to the external network by default

It can only be accessed if a valid IP address is assigned to the container. Sometimes the IP that Docker chooses for the container can conflict with external networks.

By default, containers run on a bridge network, so look:

 docker network inspect bridge 

Locate the container and check its IP.

To resolve conflicts, you can configure the bridge network and set the bip parameter to change the range of network IP addresses (config file location depends on the host OS):

 "bip": "192.168.1.5/24" 

Or create a new docker network.

Or experiment with the net=host option: docker network settings

+3
source

Does it help?

Connect to SQL Server database from docker container

In addition, Googling for this "docker connectivity to SQL Server database" seems to return many useful results.

0
source

Source: https://habr.com/ru/post/1268745/


All Articles