Categories
Uncategorized

How to restore database in a mssql docker container using .bak

Start the container and attach the local folder to the docker container

docker run -v /Users/mac/data:/sqldata -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>' -p 1433:1433 -d microsoft/mssql-server-linux:latest

Run the restore database command

sqlcmd -S localhost,1433 -U SA -P '<YourStrong!Passw0rd>' -Q "USE [master] RESTORE DATABASE [mydatabase] FROM DISK = N'/sqldata/MyBackup.bak' WITH FILE = 1, MOVE 'MyBackup' TO '/var/opt/mssql/data/MyBackup.mdf', MOVE 'MyBackup_log' TO '/var/opt/mssql/data/MyBackup_log.ldf', NOUNLOAD, REPLACE, STATS = 1"

The WITH MOVE is important