In my Azure Pipeline I created a container using docker run using the below command:
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Pa$$w0rd12' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest-ubuntu
In another task I tried listing this container with a docker ps
and it shows me the container as below:
/usr/bin/docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
afca60eb6fde mcr.microsoft.com/mssql/server:2017-latest-ubuntu "/opt/mssql/bin/nonr…" 1 second ago Up Less than a second 0.0.0.0:1433->1433/tcp, :::1433->1433/tcp nostalgic_jemison
Finishing: list docker containers
Post that I'm trying to run my dotnet integration tests which uses the above container for the SQL server. These tests are supposed to create their own DB inside the servers, run the tests and delete them. But It fails while running the tests with the below error:
Error Message:
System.AggregateException : One or more errors occurred. (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: 40 - Could not open a connection to SQL Server)) (The following constructor parameters did not have matching fixture data: DatabaseSetup databaseSetup)
---- Microsoft.Data.SqlClient.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: TCP Provider, error: 40 - Could not open a connection to SQL Server)
---- The following constructor parameters did not have matching fixture data: DatabaseSetup databaseSetup
The connection string I'm using in the integration tests are as below:
"Data Source=localhost,1433;Initial Catalog=dbname;User Id=SA;Password=Pa$$w0rd12"
I'm using Ubuntu 20.04 as the build agent. Same setup works fine on my local system on WSL with Ubuntu20.04
Update 1: I have replaced localhost with the IP address of the container in connection string. Works fine in WSL locally but it still throws the same error on Azure Pipelines.
Update 2: I have just noticed that the container stops when I run dotnet test in the pipeline. I can see container running before dotnet test but can't see the container active after dotnet test