Skip to content

Instantly share code, notes, and snippets.

@s-petit
Created December 4, 2018 09:02
Show Gist options
  • Select an option

  • Save s-petit/6c816f7c333ca65afa737f53d1d177f3 to your computer and use it in GitHub Desktop.

Select an option

Save s-petit/6c816f7c333ca65afa737f53d1d177f3 to your computer and use it in GitHub Desktop.
Execute SQL instructions on an empty SQL Server during container initialization (inside Dockerfile)
FROM microsoft/mssql-server-linux
COPY sh-location/execute-sql.sh ./
ENTRYPOINT /opt/mssql/bin/sqlservr & ./execute-sql.sh; wait
HEALTHCHECK CMD /opt/mssql-tools/bin/sqlcmd -U sa -P TheP4sswd -d MyDatabase -Q "SELECT 1"
#!/bin/bash
echo "Waiting for SQL Server to be ready..."
while [[ "`cat /var/opt/mssql/log/errorlog | grep -c 'Recovery is complete. This is an informational message only. No user action is required.'`" == "0" ]]; do sleep 5; done
echo "SQL Server is ready!"
echo "Execute SQL..."
/opt/mssql-tools/bin/sqlcmd -U sa -P TheP4sswd -d MyDatabase -Q "<SQL INSTRUCTION...>"
echo "Database is ready!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment