Cannot connect to MSSQL service container from self-hosted agents

devops engineer 0 Reputation points
2025-04-25T23:51:42.9066667+00:00

Running a pipeline on a self-hosted agent with custom ubuntu sql image that was built based on

mcr.microsoft.com/mssql/server:2022-latest

anyways, running the above image on the ms-hosted ubuntu agent is working fine but when we try to run it on our self-hosted machine it's throwing the error below.

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)`

our pipeline yaml looks like below, it seems like the mssql agent service is not starting? or shutting down?

      pool:
        name: selfhostedpool
      container:
        image: test.azurecr.io/mssql:2202image
        endpoint: ACR-serviceconnection
        env:
          ACCEPT_EULA: Y
          MSSQL_SA_PASSWORD: SomePassword
        ports:
          - 1433:1433

Azure DevOps
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.