Microsoft has not released Docker images for SQL Server for Windows Server for almost 3 years. However, since I am essentially working with Windows Server 2019 and Azure, I am sharing a script to create a local image. As a user you therefore have to help yourself.
The image is created automatically by my script based on Microsoft’s code (https://github.com/Microsoft/mssql-docker).
This is basically what happens:
- The source code from Microsoft for building the image is temporarily downloaded.
- The base image in the Dockerfile is replaced with Windows Server 2019.
- The image is created and tagged.
- The temporary folder is removed again.
The Script
https://github.com/svengrav/devops-lab/blob/main/powershell/New-SQLServerImage.ps1
# Base Image for Windows Server 2019
$Image = "mcr.microsoft.com/windows/servercore:ltsc2019"
$Tag = "my/sqlserver"
# Create Image
$SourceDir = (New-Item -Path (Join-Path $env:TEMP (New-Guid)) -ItemType Directory).FullName
$Archive = Join-Path $SourceDir "Source.zip"
$RepositoryUrl = "https://api.github.com/repos/microsoft/mssql-docker/zipball/master"
Invoke-RestMethod -Uri $RepositoryUrl -OutFile $Archive
Expand-Archive -Path $Archive -DestinationPath $SourceDir -Force
Remove-Item $Archive
$DockerDir = Join-Path $SourceDir "microsoft-mssql-docker*\windows\mssql-server-windows"
if(Test-Path $DockerDir) {
$DockerDir = Get-Item $DockerDir
$DockerFile = Get-Content (Join-Path $DockerDir dockerfile)
$DockerFile -Replace "FROM microsoft/windowsservercore", "FROM $Image" | `
Set-Content (Join-Path $DockerDir dockerfile)
docker build -t $Tag $DockerDir.FullName
}
Remove-Item $SourceDir -Recurse -Force
# Run
# docker run --name "sqlserver" -d -p 1433:1433 -e sa_password="" -e ACCEPT_EULA=Y my/sqlserver
You can start the SQL Container with:
docker run --name "sqlserver" -d -p 1433:1433 -e sa_password="" -e ACCEPT_EULA=Y my/sqlserver