Error: Failed to initialize container mcr.microsoft.com/mssql/server:2019-latest

Bharat, Vutukuri (TR Technology) 10 Reputation points
2024-08-02T10:55:14.17+00:00

Hi Team

We are using SQL containers in PR check in Github actions.

We are getting Error the following.

**Error: Failed to initialize container mcr.microsoft.com/mssql/server:2019-latest
**
We are using the following Script for SQL containers in Github actions yml file.

services:

sql-data:

image: mcr.microsoft.com/mssql/server:2019-latest

env:

SA_PASSWORD: Admin123

ACCEPT_EULA: Y

ports:

- 1501:1433

options: >- # we have to run the db creation inside of a health check or it has a high chance to fail…

--health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P \"Admin123\" -l 30 -Q \"CREATE DATABASE unifiedsearchind_automation; ALTER DATABASE unifiedsearchind_automation SET READ_COMMITTED_SNAPSHOT ON;\" || exit 1"

--health-start-period=10s

--health-interval=10s

--health-timeout=5s

--health-retries=10

Can Anyone help us on this?

SQL Server Other
{count} votes

3 answers

Sort by: Most helpful
  1. Christopher Smith 0 Reputation points
    2024-08-04T00:58:49.99+00:00

    Here's the solution that fixed my Actions workflow. We remove the health checks and add an Actions step that repeatedly attempts to connect to SQL Server and run a simple query until it succeeds, ensuring the server is fully operational before proceeding with database initialization.

    
        services:
          mssql:
            image: mcr.microsoft.com/mssql/server:2022-latest
            env:
              ACCEPT_EULA: Y
              SA_PASSWORD: ComplexPass123!
              MSSQL_PID: Express
            ports:
              - 1433:1433
        
        steps:
          - uses: actions/checkout@v4
    
          - name: Wait for SQL Server to be ready
            run: |
              echo "Waiting for SQL Server to be fully operational..."
              until /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ComplexPass123! -Q "SELECT @@VERSION" > /dev/null 2>&1
              do
                echo "SQL Server is still initializing. Waiting..."
                sleep 5
              done
              echo "SQL Server is now operational."
    
          - name: Initialize SQL Server
            run: |
              /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ComplexPass123! -i ./scripts/init-db.sql
    

  2. Azamat Tashu 0 Reputation points
    2024-08-05T03:50:53.8366667+00:00

    Starting with SQL Server 2019 (15.x) CU28, container images include the new mssql-tools18 package. The previous directory /opt/mssql-tools/bin is phased out. The new directory for Microsoft ODBC 18 tools is /opt/mssql-tools18/bin, aligning with the latest tools offering. For more information about changes and security enhancements, see ODBC Driver 18.0 for SQL Server Released.

    You can add -N -C as a workaround, like:
    /opt/mssql-tools18/bin/sqlcmd -U sa -P Password123! -Q 'select 1' -N -C

    0 comments No comments

  3. Bharat, Vutukuri (TR Technology) 10 Reputation points
    2024-08-07T09:30:06.7366667+00:00

    We replaced tools with tools18 and added -C in the command. It works for us.

    /opt/mssql-tools18/bin/sqlcmd -C -S localhost
    
    
    0 comments No comments

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.