I want to run sql script on MS SQL container setup.
If I do everything separately all works fine:
Run container
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Password" -p 1434:1433 --name ms-sql -d mcr.microsoft.com/mssql/server:2019-latest
Connect to container
docker exec -it ms-sql "bash"
Run SQL
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Password' -Q 'create database TestDB12'
But if try to do same at container creation
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Password" -p 1434:1433 --name ms-sql -d mcr.microsoft.com/mssql/server:2019-latest sh -c "/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Password' -Q 'create database TestDB12'"
sqlcmd fail to login with error
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..