Closed gogo199432 closed 1 month ago
To establish a container-to-container communication, you don't need to map the assigned host port. Simply use the network alias and the actual container port. In your case:
Server=mssql,1433
you are of course completely correct. I got so fixated on the network that I forgot about that fact... thanks for the support :)
Testcontainers version
3.8.0
Using the latest Testcontainers version?
Yes
Host OS
Windows
Host arch
x86
.NET version
8.0.200
Docker version
Docker info
What happened?
I tried setting up 2 test containers. One is a database (mssql) and the other a containerized application that would use this DB. End goal is to have an easy E2E testing setup. However with a very bare-bones setup, the app is unable to connect to the DB. I tried all possible combinations of database connection strings (ip, dns name, container name, network alias, hardcoded etc.). Tried with and without custom network. No dice. However I can connect to the DB from the host, and when I ran adminer, it could also connect. Not sure what I'm doing wrong with EF Core.
Here is the Program.cs of the test app:
Container for the app is created via dotnet publish:
And the part that creates the test containers:
Relevant log output
Additional information
No response