SQL Server 2019 on Linux RHEL Docker container and Azure Data Studio on top

SQL Server 2019 on Linux RHEL Docker container and Azure Data Studio on top

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:

docker pull mcr.microsoft.com/mssql/rhel/server:2019-CTP2.2

Downloading Docker image

Running RHEL Docker

After downloaded, started a container

docker run -e "ACCEPT_EULA=Y" -e "PASSWORD=Passw0rd" -p 1433:1433 --name sql01 -d mcr.microsoft.com/mssql/rhel/server:2019-CTP2.2

Running RHEL Docker

Let’s check everything is Ok, into the container:

docker exec -it sql01 "bash"
cat /etc/os-release
ls -la

Check the container

Create new directory in the container, just to hold the db

mkdir /var/opt/mssql/backup

Creating new directory

Downloaded test db to play with

Just for testing, I downloaded from PowerShell test db

curl -OutFile "wwi.bak" https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak

Downloaded test db

Copied it into RHEL Docker container:

docker cp .\wwi.bak sql01:/var/opt/mssql/backup

db restored

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "Passw0rd" -Q "RESTORE FILELISTONLY FROM DISK = '/var/opt/mssql/backup/wwi.bak'"

db restored

And after restored backup file, import data was needed

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'"

imported data

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

Azure Data Studio main window

Azure Data Studio databases

Azure Data Studio querying example data

Nice and easy one!

Eloy Salamanca