1

I have 2 containers:

  • database (azuresqledge)
  • application (my-dbup-app - .NET 6.0)

I can access the database container from my host machine and run the .NET application from my host machine via localhost.

When I try to run the application via Docker, the application cannot find the SQL Server instance.

Server=azuresqledge;Database=databasename;User Id=sa;password=pwd;Trusted_Connection=False;MultipleActiveResultSets=true;

System.Data.SqlClient.SqlException (0x80131904): 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)

I made sure that both are running on the same Docker Network - bridge - so that I just need to set the connection string to be the container's name, however the application fails to connect.

Portainer showing Docker Network and associated Containers

I am running on Mac M1 so need to use azuresqledge.

Is there something I'm missing in the configuration?

Thanks.

Rossimac
  • 73
  • 1
  • 7
  • 1
    How are you starting the containers; why do you think they're on the same network? In particular, if you ran `docker run` without a `--net` option, they're on the [default bridge network](https://docs.docker.com/network/bridge/) and can't actually use the usual means to communicate with each other. See for example [How to communicate between Docker containers via "hostname"](https://stackoverflow.com/questions/30545023/how-to-communicate-between-docker-containers-via-hostname/35184695#35184695). – David Maze Dec 16 '21 at 22:44
  • I was not specifying a network and so I have now created a new network and moved both of my containers to it using `docker network connect ` and it now can connect. Thank you! – Rossimac Dec 16 '21 at 23:07
  • To answer your first question, I used [Portainer](https://www.portainer.io) to view all networks and saw that my containers were on the network `bridge`. – Rossimac Dec 16 '21 at 23:16

1 Answers1

0

I have had issues with --net=host and --net=bridge on macs. I believe it might be because there is no docker0 bridge on macs.

https://docs.docker.com/desktop/mac/networking/#there-is-no-docker0-bridge-on-macos

https://forums.docker.com/t/network-bridge-on-host/12414

Have you tried manually exposing your ports? Looks like from your link azure-sql-edge wants port 1433 exposed. -p 1433:1433

Rienzi G
  • 51
  • 1
  • 5
  • 1
    I was not specifying a network with my `docker run` and so it was using the default network `--net=bridge`. I created a new network and it can now connect via container name. I was already exposing ports from the `azure-sql-edge` container. – Rossimac Dec 16 '21 at 23:16