My day to day work machine is a Windows 10 HP laptop. It remains docked at my desk where it happily helps me to go about my daily business. However, my backup machine, is an Apple MacBook Pro. It’s small footprint and ease of use allows me to easily shift working locations if needed. Of course, these days I’m maintaining social distancing so getting away from my desk to work elsewhere means working from my kitchen table for a change of scenery.
When I shift working locations I work on my Macbook, and I still need access to a SQL Server instance. Yes, I could install SQL Server on the OS but it’s my personal machine and I’m not that familiar with SQL on Linux (yet). Docker, however, it a great solution to allow me to run SQL Server containers on my Macbook without having to set up anything. Let’s look to see how easy it is to setup Docker.
Go out to docker.com, download, and install the Docker Desktop application. This is what will allow you to run container images. The images are what define the container which then in turn runs the application, which in our case is SQL Server. Once you have it installed, you’ll have a dashboard like the one shown below.
At this point, we don’t have any containers running so we need to first get a container image and then create a container. I got my image from Docker Hub, a library of container images that you can browse and subsequently download if needed. Searching for SQL Server images, we can see that Microsoft has their own registry that has a few available container images. The Feature Tags shown below show some often used images. If you scroll further down the page, you can browse the full is list of available tags that can be used to download an image.
For my purposes, using the latest and greatest for testing and validating things is perfect so I’m only interested in the “2019-latest” container image. To obtain the image, you can issue a pull command from within a terminal session. You’ll notice that Docker Hub provides you with the command in the above image.
docker pull mcr.microsoft.com/mssql/server:2019-latest.
We can check to make sure that the container image was downloaded as well as view any other images we might have. As shown below, you can see that I have three images available.
Starting the SQL Server Container
Now that we have a container image downloaded, we can now initiate setting up the container itself. Since SQL Server has already been installed within the container, it must now be configured for it to successfully start. Essentially, we need to tell Docker to run the image and pass in some parameters.
Here’s what they mean:
-e represents environment variables. Here we are accepting the end user license agreement (EULA) as well as supplying a SA password (it’s required).
-p represents the ports. The value on the left side of the colon is the port on the host and the value on the right side is the port within the container. In this example, both sides will be listening on port 1433, which is the default port for SQL.
-d represents which container image we want to run. In this example I want to run the 2019-latest image pulled from Microsoft.com.
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest
Running this command, if all is correct, will return a GUID looking value.
We can also see that the Docker dashboard now has a running instance.
Using Azure Data Studio, I can now connect to the localhost on port 1433. We can see that the version is 2019 CU4 which is the latest release for SQL Server 2019.
It’s that easy!
If you are stuck on a command, simply run docker + command + “–help” to get a list of available parameters. For example, if I need to see what parameters are available for the run command, I would type in “docker run –help”. The output would display all of the available parameters that you can supply with the “run” command.
Using Docker allows me to quickly and easily stand up an instance of SQL Server. Often times I just need an instance to test a feature or try to figure out how something works. All in all, this process takes about 5-10 minutes to finish and it significantly faster than standing up a VM. If you are new to Docker, try it out. It works on Windows too!
Watch for future blog posts on how to use Docker with SQL Server! Subscribe for email notifications when new content is posted!
© 2020, John Morehouse. All rights reserved.Contact the Author | Contact DCAC