I'm onboarding in a company that handles bootstrapping the database using a small SQL Server backup file. I prefer to avoid having to pollute my main Windows installation with various middleware, so I'd like to dockerize as much of this as possible.
That said, I'm not very familiar with SQL Server administration, so I'm somewhat at a loss as to how to accomplish the details, and if my thinking on this is at all correct.
I'm considering two basic approaches to this:
FROM microsoft/mssql-server-windows-express
to the project, restore the backup file, end up with a container image with the database ready as the end result.
docker-compose up --build
to get a correct state. My questions then are:
Its not clear exactly when you need the state of the container database to be reset, both your options sound like they'd work.
In the event that changes to the backup require the database to be rebuilt, this can be done quite efficiently in a two stage windows container:
from microsoft/mssql-server-windows-developer as db_restore
copy db.bak \.
run Invoke-Sqlcmd -Query \"restore database [temp] from disk = 'c:\\db.bak' \
with move 'Db_Data' to 'c:\\db.mdf', \
move 'Db_Log' to 'c:\\db.ldf'\"
run Invoke-Sqlcmd -Query \"shutdown with nowait\"
from microsoft/mssql-server-windows-developer
workdir \data
copy --from=db_restore \db.mdf .
copy --from=db_restore \db.ldf .
run Invoke-Sqlcmd -Query \"create database [Db] \
on primary ( name = N'Db_Data', filename = N'c:\\data\\db.mdf') \
log on (name = N'Db_Log', filename = N'c:\\data\\db.ldf') for attach\"