Created
December 4, 2018 09:02
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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