SQL Server in Windows Containers
Windows Containers are an isolated, resource controlled, and portable operating environment. An application inside a container can run without affecting the rest of the system and vice versa. This isolation makes SQL Server in a Windows Container ideal for Rapid Test Deployment scenarios as well as Continuous Integration Processes. This blog provides a step by step guide of setting up SQL Server Express 2014 in a Windows Container by using this community-contributed Dockerfile.
Prerequisites
• System running Windows Server Technical Preview 4 or later.
• 10GB available storage for container host image, OS Base Image and setup scripts.
• Administrator permissions on the system.
Setup a VM or a physical machine as a Windows Container Host
Step 1: Start a PowerShell session as administrator. This can be done by running the following command from the command line.
PS C:\> powershell.exe
Step 2: Use the following command to download the setup script. Note: The script can also be manually downloaded from this location - Configuration Script.
wget -uri https://aka.ms/tp4/Install-ContainerHost -OutFile C:\Install-ContainerHost.ps1
Step 3: After the download completes, execute the script.
PS C:\> powershell.exe -NoProfile C:\Install-ContainerHost.ps1
With these steps completed your system should be ready for Windows Containers. You can follow this link to read the full article that describes more on setting up a VM or a physical machine as a Windows Container Host.
Installing SQL Server Express 2014 in a Windows Container
Step 1: Copy all files from this community-contributed Dockerfile locally into your c:\sqlexpress folder.
Note: All files were provided by brogersyh . The Dockerfile contains all the SQL Server configuration settings (ports, passwords etc.) that you can customize if needed.
Step 2: Start a PowerShell session and run the following command:
docker build -t sqlexpress .
Starting SQL Server
Step 1: Start a PowerShell session and run the following command:
docker run -it -p 1433:1433 sqlexpress cmd
Step 2: Enter PowerShell in the Container Window by typing:
Powershell
Step 3: Start SQL Server by running the following PS Script (downloaded from step2):
./start
Step 4: Verify that SQL Server is running with the following command:
get-service *sql*
Next Steps
We are currently working on testing and publishing SQL Server Container Images that could speed up the process of getting started with SQL Server in Windows Containers significantly. Stay tuned for an update!
Further Reading
Windows Containers Overview Windows-based containers: Modern app development with enterprise-grade control.
Windows Containers: What, Why and How
Comments
- Anonymous
March 22, 2016
ist there a way to access the DB with the sql management studio?- Anonymous
March 24, 2016
Absolutely! You can access the DB from sql management studio by using the container's IP Address along with the sql authentication credentials stored in the Dockerfile (Installing SQL Server Express 2014 in a Windows Container: Step1 int he tutorial). Use the container's internal IP Address if you are accessing the DB from SSMS installed on the Host and the external IP Address if you are accessing it from another machine. Note that a firewall rule might need to be created depending upon your setup.Please refer to this article for more information regarding Container Networking: https://msdn.microsoft.com/en-us/virtualization/windowscontainers/management/container_networking.
- Anonymous
- Anonymous
March 22, 2016
What is the advantage of a Docker container running SQL Server in isolation over a VM running SQL Server in isolation? With a VM, I only need one copy of the OS bits. With a Docker container, there appears to be multiple copies of the OS bits in C:\ProgramData\docker\windowsfilter. After following the instructions above I ended up with 21GB of bloat in those folders. What's the point?- Anonymous
March 22, 2016
Thanks a lot for the feedback Paul. You can think of containers as another resource sharing option and not necessarily as a VM replacement. Depending on the scenario one option might be more suitable than the other. With that said, choosing between a container and a VM can be tricky, but I believe that this blog post: https://azure.microsoft.com/en-us/blog/containers-docker-windows-and-trends/ provides a nice overview on Containers and explains their key differences compared to VMs (Eg. namespace isolation, governing resources etc.).Hope that helps.
- Anonymous
- Anonymous
March 31, 2016
The comment has been removed- Anonymous
March 31, 2016
The comment has been removed- Anonymous
April 05, 2016
Hi Perry,Yes, I can. I've been digging a little bit more on the subject but I will post it to the forum.
- Anonymous
- Anonymous
- Anonymous
July 13, 2016
hello I have followed your steps and everything is working like a charm.Thanks you- Anonymous
July 14, 2016
Great! Thanks for trying SQL in Windows Containers SoyUnEmilio!
- Anonymous
- Anonymous
August 08, 2016
How can one attach already present mdf and log file?what exactly is happening in datatemp, start.ps1?- Anonymous
September 06, 2016
Hi Sam - Please take a look at the following section that describes how you can attach existing .mdf and .ldf files.https://github.com/Microsoft/sql-server-samples/tree/master/samples/manage/windows-containers/mssql-server-2014-express-windows#run-this-sampleCan you be a bit more specific on your datatemp, start.ps1 question?Thanks, Perry
- Anonymous
- Anonymous
September 24, 2016
Given that SQL Server uses non-preemptive scheduling and aside from two windows DLLs it is virtually bare metal when it comes to scheduling, how does resource management work with SQL Server and windows containers, in terms of constraining the CPU resource and instance uses.- Anonymous
October 04, 2016
Hi Chris - Please take a look at this: https://channel9.msdn.com/Blogs/containers/Container-Fundamentals--Part-4-Resource-Management video that walks through how to manage resources, such as CPU, disk, memory and network, for Windows Server Containers.Thanks, Perry
- Anonymous
- Anonymous
October 19, 2016
Is there an option to run full SQL Server i.e. not express, in a container?- Anonymous
October 25, 2016
Hi Andrew - Although, currently SQL Server Express is the only edition available as a Docker image, you could edit the existing Docker file: https://github.com/Microsoft/sql-server-samples/blob/master/samples/manage/windows-containers/mssql-server-2016-express-windows/dockerfile and create your own image.Thanks,Perry
- Anonymous
- Anonymous
October 31, 2016
Hi I have one container with Web site up and running on the my development machine windows 2016(I did not commit yet), of course I need to port on to docker hub. Now I need to build another container to host db sql server express. 1. I have question how to do download it on to client(windows 10) as client, I am seeing the image ps images dockker images command. How do I add it to my client through vm hyper v app? or docker run command. Also just wondering how work on db stuff now, create another container sql server express and how does this web container will see db container. app web ui taking to db server on client machine.- Anonymous
November 23, 2016
Hi Narayan -Please follow the tutorial below to get started with setting up a multi container application that includes SQL Server Express 2016. https://github.com/docker/labs/tree/master/windows/windows-containersLet me know if you run into any issues,Thanks,Perry
- Anonymous