Author : MD TAREQ HASSAN

Preparing Docker

Running SQL Server on Docker

Pull image

docker pull microsoft/mssql-server-windows-developer:2017-latest

Build and run container from image

must run commands in powershell or powershell tab in cmder

docker run `
--name FooSqlServer `
-e sa_password=FooSqlServer101 `
-e 'ACCEPT_EULA=Y' `
-p 1433:1433 `
-d microsoft/mssql-server-windows-developer:2017-latest

Test connection

Command to execute in powershell:

sqlcmd -S 172.19.29.211,1433 -U sa -P FooSqlServer101

# Show  all the variables set
1> :ListVar

Persisting data - decoupling data persistence from container

2 ways we can decouple data persistence from container (writable layer)

Decoupling by exposing host directory to container

Decoupling by using volume

docker volume create foo_volume   # default: C:\ProgramData\Docker\volumes

docker volume ls

docker volume inspect foo_volume  # will show Mountpoint

Now volume path form Mountpoint (docker volume inspect foo_volume) ND run container with -v (must use powershell or powershell tab in cmder to execute commands)

docker run `
--name FooSqlServer `
-e sa_password=FooSqlServer101 `
-e 'ACCEPT_EULA=Y' `
-p 1433:1433 `
-d microsoft/mssql-server-windows-developer:2017-latest `
-v c:\ProgramData\Docker\volumes\foo_volume:c:\foo_volume

(did not work ‘…file not found error…’ for windows container)

Notes:

Next: connecting-ssms-to-sql-server-in-docker