ASP.NET Core – problem with database and Docker

I’m currently learning to create a simple ASP.NET MVC web app with a Docker on it and once I got into creating a database I’ve got a problem.

After adding “MVC Controller with views, using Entity Framework”, once I tried to connect to the created controller, I got this:

Win32Exception: The system cannot find the file specified.
Unknown location

SqlException: 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: SQL Network Interfaces, error: 52 – Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)

What I did is went to appsettings.json and changed the connection string:

"MvcMovieContext": "Server=(localdb)mssqllocaldb;Database=MvcMovieContext-1;Trusted_Connection=True;MultipleActiveResultSets=true"

Server=(localdb) -> Server=(localdb:{port})

I’ve put a port that docker hosts the container on, without the brackets of course. And this resulted in a new error:

SqlException: 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: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)

Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, object providerInfo, string newPassword, SecureString newSecurePassword, bool redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, bool applyTransientFaultHandling, string accessToken, DbConnectionPool pool, SqlAuthenticationProviderManager sqlAuthProviderManager)

And I have no idea what to do now. I googled for a while now, but I probably don’t even know what to look for. I’m pretty sure I have missed a basic thing resulting in this error and I hope someone can point it out here.

The tutorial I’m talking about:
https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-model?view=aspnetcore-3.1&tabs=visual-studio

Of course I am aware that the tutorial itself is not using Docker, and my app works perfectly fine without it, I just personally need to learn Docker and work with it.

Source: StackOverflow