One of the things about working with SQL in Docker is that you kinda have to use the images that are on the Docker Hub. Now this is great if you want SQL Server 2016 or 2017 but what about earlier versions?
Now, this is a bit involved so I should point out WinDocks.com. They have a great product which allows earlier versions of SQL Server to run in containers on earlier versions of Windows Server which means you don’t have to go through all this.
But I wanted to try this to see if I could get it done. I’ve noticed that there aren’t any images for SQL Server 2014 SP2 Developer Edition on the Docker Hub (not that I can find anyway) so I thought I’d build one myself.
TL;DR – If you want to skip all of this you can download the image I’ve build from the Docker Hub by running:-
docker pull dbafromthecold/sqlserver2014dev:sp2
I’m running all of this on my Windows 10 machine but there are a few things you’ll need before we get started: –
- The microsoft/windowsservercore image downloaded from the Docker Hub
- Windows Server 2016 installation media extracted to
- SQL Server 2014 SP2 Developer Edition installation media extracted to C:\Docker\Builds\SQLServer2014
First thing to do is build an image of Windows Server 2016 Core with .Net 3.5 installed. So first we will create a container running windows server 2016 with the installation media copied into it. Then we’ll install .Net 3.5.
So, build the container: –
docker run -it -v C:\Docker\Builds\Windows\en_windows_server_2016_x64_dvd_9718492\sources:C:\install --name buildcontainer1 microsoft/windowsservercore
This will copy the files under the source folder to C:\install within the container. Once the container is up and running, the -it switch will open a remote session into the container. So then we run: –
cd c:\install powershell Install-WindowsFeature –name NET-Framework-Core –source c:\install\sources\sxs
Cool, so exit out of that container and commit it as a new image: –
docker commit buildcontainer1 windowscorenet
All good so far. What we’re going to do now is spin up a new container from that image with the SQL Server 2014 installation media copied into it: –
docker run -it -v C:\Docker\Builds\SQLServer2014\sql_server_2014_dev_sp2:C:\SQL2014 --name buildcontainer2 windowscorenet
Once that’s up and running we (should) have a command window in the container. Now we need to install SQL so run: –
C:\sql2014\setup.exe /q /ACTION=Install /FEATURES=SQL /INSTANCENAME=MSSQLSERVER /SECURITYMODE=SQL /SAPWD="Testing11@@" /SQLSVCACCOUNT="NT AUTHORITY\System" /SQLSYSADMINACCOUNTS="BUILTIN\Administrators" /TCPENABLED=1 /IACCEPTSQLSERVERLICENSETERMS
Once that’s done, exit out of the container and save it as a new image: –
docker stop buildcontainer2 docker commit buildcontainer2 sqlserver2014dev:sp2
Awesome stuff! But has it worked? Can we spin up a new container and have SQL 2014 up and running? Let’s give it a whirl: –
docker run -d -i -p 14567:1433 --name testcontainer2014 sqlserver2014dev:sp2
N.B. – The -i flag has to be used with the run command to stop the container from exiting immediately (it’ll stay up in the background). I’ve looked through the documentation on the -i flag but am kinda unsure as to why this works. If you know, let me know! (please) 🙂
Now we need to get the IP address that the container is listening on: –
docker inspect testcontainer2014
My container is listening on port 172.26.126.99 so I’ll open up SSMS on my local machine, enter the sa username/password and: –
SQL Server 2014 SP2 Developer Edition running in a container that’s been build from a custom image!
I’d love to get all of this into a Docker File so I think that’ll be the next thing to do.
Thanks for reading!