Skip to content

Instantly share code, notes, and snippets.

@danielmackay
Last active July 29, 2024 11:24
Show Gist options
  • Save danielmackay/02abdca8c3e650d1aea890df37a3d49f to your computer and use it in GitHub Desktop.
Save danielmackay/02abdca8c3e650d1aea890df37a3d49f to your computer and use it in GitHub Desktop.
Create an empty database on a fresh SQL Server on MacOS
Server=localhost,1600;Initial Catalog=$DB_NAME;Persist Security Info=False;User ID=sa;Password=yourStrong(!)Password;MultipleActiveResultSets=True;TrustServerCertificate=True;Connection Timeout=30;
services:
db:
environment:
ACCEPT_EULA: "Y"
SA_PASSWORD: "yourStrong(!)Password"
DB_NAME: DansSweetDB
# mssql server image isn't available for arm64 architecture, so we use azure-sql instead
#image: mcr.microsoft.com/azure-sql-edge:latest
# If you really want to use MS SQL Server, uncomment the following line
image: mcr.microsoft.com/mssql/server
container_name: sqlserver
platform: linux/amd64
ports:
- 1600:1433
volumes:
- ./init-db.sh:/usr/src/app/init-db.sh
command: /usr/src/app/init-db.sh
restart: unless-stopped
#!/bin/bash
# Start SQL Server
/opt/mssql/bin/sqlservr &
# Wait for SQL Server to start
# NOTE: You may need more or less time for SQL Server to start
sleep 10s
# Run SQL commands
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "CREATE DATABASE $DB_NAME;"
# Wait for SQL Server to stop
wait
# NOTE: Don't forget to give this file executable permissions via 'chmod +x'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment