Worth Corner, Crawley, RH10 7SL

Support Hours - Mon-Sat, 8.00-18.00

Welcome to our SQL Server blog

This blog was created in order to pass on some of our knowledge and advice in the hope that the community might find it useful.

Obviously Microsoft SQL Server is our area of expertise and therefore this is our most thorough blog with everything from the basic through to the the incredibly advanced and, as such, we should have something for everyone within our pages.


Linux SQL Server on Windows with Docker
Published: Jan 20, 2022
First things first, we need to get started. This means downloading and installing Docker. Only then can we start to get to work with SQL Server on Docker.

Luckily there are guides for this from the Docker website itself and therefore I’ll leave that detail up to them.

Once you’ve installed it on your desktop then come back and I’ll get you started with a basic SQL Server setup.

Note that Docker desktop is found in the hidden icons on your Taskbar:


You can see the icon and the tooltip that pops up to let us know that not only is Docker there, it’s also running.

If you don’t have this icon then you need to go to your Start bar and click Docker Desktop:


Okay, so let’s presume you’re now up and running.

Docker defaults to Linux Containers as standard and we’re going to leave it that way for the moment and boot up SQL 2019 on Linux, although if you do want to switch to Windows Containers (don’t do this for this demo) that’s easy, you just need to Right Click the Docker Icon and you’ll see this:


Anyway, as mentioned, I’m sticking with Linux so that I can boot SQL Server on Linux within my Windows box.

At this point you can choose to either open a Command Prompt or PowerShell window. As a PowerShell convert I’m going to open that:


Note, I’ve done mine in Admin mode… this is because if you’ve never used Docker before then you’ll need to install the PowerShell modules by running:

Register-PSRepository -Name DockerPS-Dev -SourceLocation https://ci.appveyor.com/nuget/docker-powershell-dev


Install-Module Docker -Repository DockerPS-Dev


We need to go and get our Container. So we’ll open Microsoft’s Container store for Linux SQL Server:

https://hub.docker.com/_/microsoft-mssql-server


We’ll go down this list and fine the latest 2019 version:


So what I’ll do now is to run that command and it’ll start downloading:


Once done it will look like this:


That took me maybe a few mins to download (it’s about 1.3GB)… and, ridiculously, that’s it. I now have a functioning SQL Server 2019 on Linux.

Don’t believe me? Go to PowerShell and type the following:

docker run --name SQL2019Linux -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong123Password' -p 14330:1433 -d mcr.microsoft.com/mssql/server:2019-latest


You now have a working SQL Server.

NOTE – You can see in the command above I used port 14330 on my desktop to map to port 1433 in the Container. This is because I already have a SQL Server installed on my local machine and therefore didn’t want the port clash.


Let’s verify this by running the following:

docker exec -it SQL2019Linux /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P yourStrong123Password


This will open up a SQLCMD for us which we can then query to see what version we’re using:


Bingo. We now have SQL Server 2019 Linux running on a Windows Desktop.

Now, just to double back briefly, as I don’t want to leave any stone unturned yet didn’t want to interrupt the above “look how quick this is” commentary…

When running the SQL Server Run Container command we use “--name” in order to name the Container. This is NOT the name of the SQL Server Instance. It is the name of the Container we have just created from the Downloaded Image.

We HAVE to accept the EULA because this would, otherwise, be a stopping point in the boot process and we don’t have a two-way console and therefore the request for Y would go unheeded and nothing would run. So we need to state that up front. You do need a strong SA Password otherwise SQL Server will not let you log in. And, finally, we use -p to map a desktop port (try to find an unused one) to the port we require inside the container. SQL Server uses port 1433 and therefore we map an empty port on our desktop (in my case 14330) to 1433 inside the container.

When running SQLCMD we are telling docker to run the command interactively inside the container. This is the purpose of “-it”. We therefore say “Docker, inside container SQL2019Linux, run this command”. You should know the rest (server, user, password).

Leave a Comment
Your email address will not be published. All fields are mandatory.
NB: Comments will only appear once they have been moderated.

SQL  World  CEO
Kevin  Urquhart

iPhone Selfie

I am a SQL Server DBA, Architect, Developer, Trainer, and CEO of SQL World. This is my blog in which I’m simply trying to share my SQL knowledge and experiences with the world.

Categories


© Copyright 2020 SQLTraining Ltd.