ilhan DEMİRTEPE
ParamTech
Published in
2 min readAug 27, 2022

--

Why use docker ?

Docker technology, is an open source technology. At its core, it is used to develop, distribute and run applications.Docker allows you to isolate applications from a local infrastructure. This makes software deployment faster, easier and more secure than ever before.For example running sql server in a docker container

The advantages of running sql server in a docker container

1-Fast installation

No installation needed if you already have docker installed.

2-Automatic installation/deploy

You can start SQL with just few commands, no need for user interactive process. Very useful for CI/CD pipeline.

3-Cheap

Windows-based virtual servers are more expensive than Linux. Testing your solution could be done on Linux runners and save you money.

4-Testing against different servers/version

You can test your solution with different version on SQL server with just changing the tag of an image or SQL Server type in environment var

5-Cross-platform

Developers can use different operating systems when working on big project (our case). Docker configuration will run on any without changes. Maybe you designes use MacOS and also want to run solution locally? Easy with Docker.

sql server create docker container and restore backup

1-Create Sql Container →(USE COMMAND PROMPT)

docker run -e “ACCEPT_EULA=Y” -e “SA_PASSWORD=VAN65TEST123” -p 1433:1433 — name lcwaikiserver -h lcwaikiserver -v sqlvolumewaikiki:/var/opt/mssql
-d mcr.microsoft.com/mssql/server:2019-latest

2 -Create Container Backup Directory →(USE COMMAND PROMPT)

Docker exec -it lcwaikiserver mkdir /var/opt/mssql/ilhanbackups

3-Copy the backup file from local server to container server(USE COMMAND PROMPT)

Docker cp C:/dbbackups/TESTDB_LCW.bak lcwaikiserver:/var/opt/mssql/ilhanbackups

4-Check Data Path →(USE MİCROSOFT SQL SERVER MANAGEMENT STUDİO)

RESTORE FILELISTONLY FROM DISK=N’/var/opt/mssql/ilhanbackups/TESTDB_LCW.bak’

5-Restore Data →(USE MİCROSOFT SQL SERVER MANAGEMENT STUDİO)

USE master;
GO
RESTORE DATABASE TESTDB_LCW FROM DISK=N’/var/opt/mssql/ilhanbackups/TESTDB_LCW.bak’ WITH
MOVE ‘TESTDB’ to ‘/var/opt/mssql/data/TESTDB.mdf’,
MOVE ‘TESTDB_log’ to ‘/var/opt/mssql/data/TESTDB.ldf’
GO

--

--