https://www.docker.com/
name: "dotnet-app"
version: "3.8"
volumes:
sqldata:
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2022-latest
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=passW0rD.222a
- MSSQL_PID=Developer
user: root
ports:
- "1433:1433"
volumes:
- ./.database/init.sql:/.database/init.sql
- ./.database/entrypoint.sh:/entrypoint.sh
entrypoint: ["/bin/bash", "/entrypoint.sh"]
#!/bin/bash
# Start SQL Server in the background
/opt/mssql/bin/sqlservr &
# Wait until SQL Server is ready
echo "Waiting for SQL Server to be available..."
until /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "imp.neT772alL" -C -Q "SELECT 1" > /dev/null 2>&1; do
sleep 1
echo "Still Waiting for SQL Server to be available..."
done
# Run your init script
echo "Running init.sql..."
/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "imp.neT772alL" -C -i /.database/init.sql
echo "Finished running init.sql."
# Keep container alive
wait
entrypoint.sh is needed as MS SQL doesn’t have a proper and easier way to initialise data like mySQL or others.