This is one of the ways Connecting to SQL Server container hosted inside Docker
.
Assuming that you have executed the below-mentioned command to execute the SQL Server 2019
container.
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Sample123$" -p 1433:1433 --name mssql2019indocker -d mcr.microsoft.com/mssql/server:latest
Azure Data Studio:
You can use server=localhost
, Authentication Type=SQL Login
, User name = sa
, and password = Sample123$
. These details are based on the command you have executed which creating the container. Please refer to the image below.
Azure Data Studio to Login into SQL Server 2019 Docker Container

Note: If you are using the EF Core tools to migrate the database the server should be "localhost" as shown in the Azure Data Studio login image.
.NET Core application connecting to Docker Container
Here the situation is .NET core
application is executing in one Docker container, and SQL Server 2019
is executing in another container.
Please execute the below-mentioned command to find out the IPAddress of the SQL Server 2019 Docker
container. Please refer to the image below. In my scenario, the IPAddress is 172.17.0.3.
docker inspect <ContainerIdOfSQLServer2019>
Once you get IPAddress, please update it in the below-mentioned connection string.
Server=<IPAddressOfTheSqlServer2019DockerContainer>;Database=myDataBase;User Id=myUsername;Password=myPassword;
Finding IP Address of SQL Server 2019 Docker container

Executing the Web App with Docker Configuration
