Restoring MSServer Backups with Docker and Linux

Restoring Microsoft SQLServer with Docker and Linux

This fast tip I learned with a friend.

So, to execute a MSServer container and restore backup, follow the steps:

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourPass' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-CU8-ubuntu

docker exec -it <container_name> mkdir /var/opt/mssql/backup
docker cp <file>.bak <container_name>:/var/opt/mssql/backup
docker exec -it <container_id|container_name> /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P <your_password>
RESTORE DATABASE databaseName
FROM DISK = '/var/opt/mssql/backup/nameFile.bak'
WITH MOVE 'databaseName' TO '/var/opt/mssql/data/nameFile.mdf', MOVE 'nameFile_Log' TO '/var/opt/mssql/data/nameFile_Log.ldf'
GO
SELECT Name FROM sys.Databases
GO

and that’s all folks!

If you have any doubts, problems or suggestions, just leave a message.

No Comments Yet