File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -46,15 +46,16 @@ RUN /bin/bash /tmp/start-sql.sh
4646FROM dbatools/mssqlbase
4747COPY --from=builder /var/opt/mssql /var/opt/mssql
4848COPY --from=builder /opt/mssql-tools/bin /opt/mssql-tools/bin
49+ COPY --from=builder /tmp/post-entrypoint.sh /opt/mssql/bin/post-entrypoint.sh
4950
5051# make a shared dir with the proper permissions
5152USER root
5253RUN mkdir /shared; chown mssql /shared
5354
5455# run a rootless container
5556USER mssql
56- ENTRYPOINT /opt/mssql/bin/sqlservr
57- # CMD exec / bin/bash -c "trap : TERM INT; sleep infinity & wait"
57+ # create a new database if env var is set
58+ ENTRYPOINT /opt/mssql/ bin/sqlservr & /opt/mssql/bin/post-entrypoint.sh
5859
5960# label the container
6061LABEL org.opencontainers.image.vendor="dbatools"
Original file line number Diff line number Diff line change 1+ # if an environment variable for newdb exists, create it
2+ if [ -n " ${MSSQL_DB+1} " ]; then
3+ # load up environment variables
4+ export SQLCMDSERVER=localhost
5+ export SQLCMDUSER=sqladmin
6+ export SQLCMDPASSWORD=dbatools.IO
7+ export PATH=$PATH :/opt/mssql-tools/bin
8+
9+ # wait for sql to be ready
10+ for i in {1..30};
11+ do
12+ sqlcmd -S localhost -d master -Q " SELECT @@VERSION"
13+ if [ $? -ne 0 ]; then
14+ sleep 2
15+ fi
16+ done
17+
18+ # create the db if it doesn't exist already
19+ sqlcmd -S localhost -d master -Q " IF DB_ID (N'${MSSQL_DB} ') IS NULL CREATE DATABASE ${MSSQL_DB} ;"
20+ fi
21+
22+ # keep it going
23+ sleep infinity
You can’t perform that action at this time.
0 commit comments