简体   繁体   中英

Cannot connect Docker Container to another Container

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.

展示 Docker 网络和相关容器的搬运工

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

Is there something I'm missing in the configuration?

Thanks.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM