Create a SQL Server database
Init script
Section titled “Init script”Fill in the variables above and set the login’s password in the script:
CREATE DATABASE ${{ DATABASE }};GOUSE ${{ DATABASE }};GOCREATE LOGIN ${{ USERNAME }} WITH PASSWORD = 'put_your_password';GOCREATE USER ${{ USERNAME }} FOR LOGIN ${{ USERNAME }};GORun with sqlcmd
Section titled “Run with sqlcmd”Set the SA password in your shell, then run the script. SQL Server 2022 ships
sqlcmd at /opt/mssql-tools18/bin/ and enforces TLS by default — -C trusts a
self-signed server certificate (use -N to control encryption mode explicitly):
export SA_PASSWORD=put_your_sa_password/opt/mssql-tools18/bin/sqlcmd -S "${{ HOSTNAME }},1433" -U SA -P "$SA_PASSWORD" -C -i /sqlserver-init.sql;Legacy mssql-tools
Section titled “Legacy mssql-tools”On older images the binary lives at /opt/mssql-tools/bin/sqlcmd (no TLS by
default). Drop the -C flag and adjust the path:
/opt/mssql-tools/bin/sqlcmd -S "${{ HOSTNAME }},1433" -U SA -P "$SA_PASSWORD" -i /sqlserver-init.sql;