Install MSSQL Server 2016 in Windows Container
In this blog, we will show you how to install MSSQL Server 2016 in Windows Container using windows server core image.
- Windows Container Host with docker installed
- SQL Installation Files
- Windows 2016 Server Core container image
Note: In this demonstration, we are using windows container host as VM using nested virtualization
- Open the web browser, and go to https://www.microsoft.com/en-in/evalcenter/evaluate-sql-server-2016 URL and download the SQL Server 2016 with SP1.
- It will download an executable file named SQLServer2016-SSEI-Eval.exe.
- Double Click on the executable as shown below.
- Click on Download Media option and select the language, package type & download location. Then Click Download.
- MSSQL image will start download it will take several minutes to complete.
- Once the download is complete, mount the MSSQL ISO.
- Copy the setup files into a folder named SQL2016.
DOTNET SETUP FILES
- Mount the Windows 2016 ISO on container host VM.
- Right on D: drive and click on open.
- Go to sources folder and copy the sxs folder to C:\SQL2016 folder.
GENERATING UNATTENDED FILE FOR MSSQL INSTALLATION
- There are several ways to generate unattended file MSSQL installation. We ran the MSSQL installation setup wizard to collect the configuration data for the unattended installation.
- Copy the Configuration file to C:\SQL2016 folder.
- We have uploaded our configurationfile in github repository. Please use the below URL to download it.
INSTALLING MANAGEMENT STUDIO
- Open the web browser and access the below URL.
- Click on Download SQL Server Management Studio – 17.0 link.
- Once its download, double-click on the installation file. It shows the welcome page of the installation wizard. Click on Install button.
- It will take several minutes to complete the installation.
- Click Close to complete the installation.
CREATING CONTAINER FOR MSSQL
- We have already pulled the windows server core image from docker hub.
- Launch a MSSQL container using the below command.
docker run -it --name sql -p 1433:1433 -v c:\sql2016:c:\sql microsoft/windowsservercore:latest cmd
docker run – It’s a sub-command to execute the docker commands.
-it – To run interactive session.
-p 1433:1433 – Binds port 1433 on the host to port 1433 on the container.
-v c:\sql2016:c:\sql – Mapping the source folder from container host (C:\sql2016) to destination folder (C:\sql) inside the container.
microsoft/windowsservercore:latest – container image with the latest tag.
cmd – Execute a process (command prompt) in the container.
- After few seconds, the container will create as shown below.
- Verify the SQL folder is available using directory listing command.
INSTALL DOTNET FEATURE
- For pre-requisites, we need to install ASP.NET feature before installing MSSQL server. Execute the below command to install this feature.
Install-WindowsFeature -Name net-framework-features -IncludeAllSubFeature -Source C:\sql\sxs\
- It will take few minutes to complete the installation.
INSTALL MSSQL SERVER
- Execute the below command, to install MSSQL in unattended mode from the command prompt.
- It will take several minutes to complete the installation. Once it's completed it returns back to command prompt.
Note : In this demonstration, we set sa useraccount password as test@123
- At last, set the SQL server service to run under LocalSystem using the below command.
sc config MSSQLSERVER obj=LocalSystem
VERIFYING THE INSTALLATION
- In the remote VM (outside the container host), Go to start menu and click on Microsoft SQL Management Studio.
- In the server connect dialog box, provide the container host IP address and sa account credentials.
- If the MSSQL is installed correctly, we will able to logged into the MSSQL container successfully.
- You need to use the container IP to access the MSSQL server from the container host. Go to the container and type ipconfig to verify the IP address.
- Open the Microsoft SQL Management Studio from the container host and provide the below details.
Server IP: 172.28.230.44
Password: <sa account password>
- After successful authentication, you will able to view the MSSQL server using container IP.
SAVING CONTAINER AS IMAGE
- Go-to container, and press ctrl+pq keys to disconnect from the container.
- Type docker ps command to verify the container state.
- Execute the docker stop command to stop the container.
- Save the image using docker commit command.
docker commit sql mssql2016
- Type docker images command to verify the MSSQL container image.
Thanks for reading this blog. We hope it was useful for you to learn how to install SQL server on windows container.