Having SQL Server on a Docker container is one of the best ideas I discovered; not only to keep my computer always clean, but also for performance and the ability to start again and again from scratch my testings; very very easy and fast.
This time I wanted to test SQL Server 2019 on Linux Red Hat; the results didn’t disappoint me at all. Also, I tested Azure Data Studio; a cross-platform database tool; previously released as the preview name SQL Server Studio
Let’s see how was the process:
Prerequisites to run SQL Server image on Docker
- Docker Engine 1.8+ on any supported Linux distribution or Docker for Mac/Windows. For more information, see Install Docker.
- Docker overlay2 storage driver. This is the default for most users. If you find that you are not using this storage provider and need to change, please see the instructions and warnings in the docker documentation for configuring overlay2.
- Minimum of 2GB of disk space.
- Minimum of 2GB of RAM.
Preparing the environment
Downloading Docker image
Once Docker up and running at my system, I downloaded docker image:
1 docker pull mcr.microsoft.com/mssql/rhel/server:2019-CTP2.2
Running RHEL Docker
After downloaded, started a container
1 docker run -e "ACCEPT_EULA=Y" -e "PASSWORD=Passw0rd" -p 1433:1433 --name sql01 -d mcr.microsoft.com/mssql/rhel/server:2019-CTP2.2
Let’s check everything is Ok, into the container:
1 2 3 docker exec -it sql01 "bash" cat /etc/os-release ls -la
Create new directory in the container, just to hold the db
1 mkdir /var/opt/mssql/backup
Downloaded test db to play with
Just for testing, I downloaded from PowerShell test db
1 curl -OutFile "wwi.bak" https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak
Copied it into RHEL Docker container:
1 docker cp .\wwi.bak sql01:/var/opt/mssql/backup
1 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "Passw0rd" -Q "RESTORE FILELISTONLY FROM DISK = '/var/opt/mssql/backup/wwi.bak'"
And after restored backup file, import data was needed
1 docker exec -it sql01 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "<YourNewStrong!Passw0rd>" -Q "RESTORE DATABASE WideWorldImporters FROM DISK = '/var/opt/mssql/backup/wwi.bak' WITH MOVE 'WWI_Primary' TO '/var/opt/mssql/data/WideWorldImporters.mdf', MOVE 'WWI_UserData' TO '/var/opt/mssql/data/WideWorldImporters_userdata.ndf', MOVE 'WWI_Log' TO '/var/opt/mssql/data/WideWorldImporters.ldf', MOVE 'WWI_InMemory_Data_1' TO '/var/opt/mssql/data/WideWorldImporters_InMemory_Data_1'"
Azure Data Studio
After downloaded Azure Data Studio (I do prefer the “zip” version, as I can leave it in the cloud), everything was accesible
Nice and easy one!