A Docker Compose Lab for the Azure SQL Database Container

A script that runs on SQL Server doesn’t always run on Azure SQL Database. USE fails, there’s no SQL Server Agent, and new databases start with different defaults. To see those differences for yourself, you needed a database in Azure. Microsoft’s Azure SQL Database container runs the Azure SQL Database engine on your own machine, with no Azure subscription, and the image is public on the Microsoft Container Registry.[1] Microsoft describes it as a target for local development, automated tests and continuous integration, not for production.[2]

A developer adjusts a valve on a glass container holding a glowing database, with a small safe beside her laptop linked by a gold thread.

I built a small lab around the container with GitHub Copilot CLI, which wrote most of the code while I directed the design and the testing. It has a Docker Compose project, start and stop scripts for Windows and for Linux and macOS, and two tests. It’s public, under the MIT licence.[3] This post covers how to use it, why it handles the sa password the way it does, and what I found while testing it.

Preview note. The container is in public preview, so details may change between builds. The results in this post come from image digest sha256:8323f47dad34124f391413c3c3182ca89da5632888df6cfb5326574026599c57, which reports Microsoft SQL Azure (RTM) - 12.0.2000.8, built November 17, 2026. The lab’s README records the same build with its test results.

What’s in the Lab

Path What it does
compose/compose.yaml One engine container, a named data volume, a healthcheck, and the sa password as a Compose secret
compose/sqldb-entrypoint.sh Reads the secret and starts the image’s normal entrypoint
scripts/Start-AzureSqlDbLab.ps1 Windows: reads the password from Credential Manager and starts the lab in a WSL distribution
scripts/Stop-AzureSqlDbLab.ps1 Windows: stops the lab, and can remove the container or the data volume
scripts/Invoke-AzureSqlDbLabSql.ps1 Windows: runs a .sql file or a query in the lab
scripts/*.sh The same three jobs on Linux and macOS
tests/change-tracking/ A Change Tracking test you can rerun on each new build
tests/functions-trigger/ An end-to-end Azure Functions SQL trigger test

The Windows scripts run in Windows PowerShell 5.1 and in PowerShell 7.

Docker Engine in WSL

Microsoft supports Windows 11 as a host through WSL 2, the Windows Subsystem for Linux.[4] The tested runtimes include Docker 24 or later, Podman, Rancher Desktop, and WSL containers (wslc), which ship with WSL.[5] The lab uses Docker Engine with the Compose plugin inside a WSL distribution. I tested it with Debian 13, Docker 29.8.2 and Compose 5.6.0. Docker Desktop isn’t needed. Docker’s Debian page covers the install.[6]

Two settings in the distribution make the scripts work. Turn on systemd in /etc/wsl.conf, so the Docker service starts with the distribution.[7] Add your Linux user to the docker group, so the scripts don’t need sudo. Docker warns that the group grants root-level privileges, so treat it as administrator access.[8]

Give the WSL VM at least 2 CPU cores, 4 GB of memory and 10 GB of free disk. Those are Microsoft’s minimums for the runtime.[9]

Store the Password in Credential Manager

The Windows scripts read the sa password from a generic credential in Windows Credential Manager. Create it with cmdkey, and leave the value off /pass. cmdkey then prompts for the password, so it never appears on the command line.[10]

PSReadLine, the module that handles editing and history in the PowerShell console, writes your commands to a history file on disk. It skips lines that contain password, asplaintext, token, apikey or secret, and version 2.2.0 and later use the parsed command to decide.[11] On this workstation, PSReadLine 2.4.5 in PowerShell 7 marked cmdkey /generic:demo /user:sa /pass:Hunter2zz! for the history file. PSReadLine 2.0.0 in Windows PowerShell 5.1 kept that line out, but only because its older pattern matches key, which is part of cmdkey. With the prompt, the password is never part of the line PSReadLine saves.

The password needs at least 8 characters, with at least three of upper case, lower case, digits and symbols.[12]

Start, Query and Stop

Clone the repository, then start the lab:

-Pull gets the current image. -KeepAlive starts a hidden sleep infinity in the distribution. WSL shuts down an idle distribution after instanceIdleTimeout milliseconds, 15000 by default, and the container stops with it.[13] The script waits for the healthcheck, creates a database named appdb, and prints the connection details. Use -Distro if your Docker distribution isn’t named Debian.

Then run something:

build-check.sql reports the engine version and SERVERPROPERTY('EngineEdition'), which is 5 for Azure SQL Database. To stop the lab:

The first form keeps your databases in the volume. The stop script gives the engine 60 seconds to shut down. In one of my tests, Docker’s default 10-second timeout ran out and Docker killed the engine (exit code 137).

On Linux and macOS, the start script takes the password on standard input, or prompts for it without echoing:

Where the Password Goes

Microsoft’s examples pass the sa password in the MSSQL_SA_PASSWORD environment variable, with docker run -e or a Compose environment: block.[14] I couldn’t find a documented password-file option. Docker keeps environment variables in the container’s configuration under .Config.Env, where docker inspect returns them to anyone who can run Docker.[15] Microsoft’s quickstart for the SQL Server image says the variable is visible in ps -eax output.[16] Docker’s Compose documentation says passwords in environment variables risk unintentional exposure, and offers secrets instead.[17]

The lab uses a Compose secret:

  1. The start script reads the password from Credential Manager, or from standard input on Linux and macOS.
  1. It sends the password through standard input to a file in a private directory, never as an argument. On Windows, the directory is on the WSL distribution’s tmpfs (/dev/shm), which is in memory. The bash script uses $XDG_RUNTIME_DIR or /dev/shm when it can. On macOS, which has neither, it falls back to $TMPDIR, which is on disk.
  1. Compose mounts the file in the container as /run/secrets/sa_password.
  1. sqldb-entrypoint.sh reads the file, exports MSSQL_SA_PASSWORD for the engine’s own processes, and runs the image’s launch script.
  1. The healthcheck and the SQL scripts give the password to sqlcmd in SQLCMDPASSWORD, which sqlcmd reads in place of -P.[18] Each one sets the variable for that one process.
  1. When the engine is healthy, the start script deletes the file. The running container keeps its mount.

The relevant part of compose.yaml:

The password isn’t in compose.yaml, in docker inspect, or on a command line on the host. On Windows and Linux, it isn’t on the host’s disk either. Anyone who can run docker exec in the container can still read the secret file or the engine’s environment. That takes Docker access, which is root-level access on the host anyway.

Two things to know:

  • Restart with the start script, not docker restart. The secret’s source file is gone after startup, so Docker can’t mount it again. The start script writes a new file and recreates the container. Your databases are in the volume and survive that.
  • The password applies only to a new volume. On an existing volume, the engine keeps the current sa password and ignores MSSQL_SA_PASSWORD. To change it, run ALTER LOGIN [sa] WITH PASSWORD = ... first, then update the stored credential.[19]

Connecting

The lab listens on 127.0.0.1,14331, on loopback only. A port published without an IP address listens on all interfaces, where other machines can reach it.[20] With WSL’s default NAT networking, a port bound to localhost in the VM is forwarded to localhost on Windows, so Windows tools connect to the same address.[21] The lab uses 14331 so it doesn’t collide with a SQL Server instance on 1433. Change it with -Port.

The container offers a self-signed certificate. Keep encryption on, and build the connection string with your driver’s builder:

TrustServerCertificate tells the driver not to validate the server’s certificate, and Microsoft describes it as not recommended. Without that validation, a man-in-the-middle attack is possible.[22] It’s acceptable for a container on loopback. Don’t carry it into a connection string for Azure or a shared server. I’ve written more about encryption in Finding Unencrypted SQL Server Connections, and the Instances That Accept Them and about the builder in SQL Server Connection Strings, and Why I Build Them the Way I Do (available 2026-12-04).

Writing SQL for This Engine

USE returns Msg 40508, so name the database in the connection: Database=appdb, or -d appdb for sqlcmd.[23] Create databases on a master connection.

If your setup script creates a database only when it’s missing, check sys.databases. The lab’s start scripts use this on the container:

Microsoft’s getting-started page uses IF DB_ID('appdb') IS NULL CREATE DATABASE appdb;.[24] On Azure SQL Database, DB_ID returns a value only for the current database.[25] On a master connection to the container, DB_ID(N'appdb') returns NULL even after the database exists. The guard works the first time, then fails with Msg 1801 on a rerun against a persistent volume. I opened a pull request to change the guard on the getting-started page,[26] and an issue for the same guard in Microsoft’s SQL agent skills.[27]

New databases also differ from SQL Server’s defaults. On the container, appdb came up with read committed snapshot on, accelerated database recovery on, and compatibility level 170.

Rehearsing a Migration

The scripts take a project name, container name, volume and port, so a migration test can run next to your everyday lab:

Deploy the schema the way you normally would: a DACPAC with SqlPackage, migration scripts, or your ORM’s migrations, pointed at 127.0.0.1,14332. Run your tests, then remove everything:

For repeatable runs, pin the image by digest with -Image mcr.microsoft.com/mssql/azure-sql-db-server@sha256:..., so a new preview build can’t change the results between runs. Give each build its own volume. The image’s launch script records a format marker on the volume and refuses a volume it doesn’t support. For the planning side of a migration, see Migration Runbook Rollback Points for SQL Server Upgrades.

The container doesn’t replace a test in Azure. Microsoft recommends testing against Azure SQL Database before production, and lists features the container leaves out.[28]

Change Tracking and the Functions Trigger

Microsoft’s FAQ lists Change Tracking among the capabilities the container doesn’t include.[29] On the build I tested, it works. ALTER DATABASE ... SET CHANGE_TRACKING = ON, ALTER TABLE ... ENABLE CHANGE_TRACKING and CHANGETABLE(CHANGES ...) all succeed, and sys.change_tracking_databases lists the database. The lab’s tests/change-tracking/Test-ChangeTracking.ps1 checks this, so you can rerun it on each new build. I opened an issue to ask which is correct, the FAQ or the engine.[30]

The Azure Functions SQL trigger uses Change Tracking to detect inserts, updates and deletes.[31] The lab’s tests/functions-trigger/Test-FunctionsTrigger.ps1 runs a .NET 8 isolated function against the container, with Azure Functions Core Tools 4.16.0, Microsoft.Azure.Functions.Worker.Extensions.Sql 3.1.549, and Azurite for the host’s storage. The trigger started, created its lease tables in the az_func schema, and delivered each change within a second or two. Change Tracking reports net changes, so a row inserted and then updated between polls arrives as one Insert with the new values.

The test needs a login for the function. The Functions host reads its connection string from local.settings.json or from environment variables, so the script creates a throwaway login and writes its password only into a temporary local.settings.json. It drops the login and deletes the file when it finishes.

Try It

The repository’s README has the rest: the Linux and macOS environment variables, a troubleshooting table, and how to report a security problem privately. If you try the lab on a different runtime, or find a build where something above changes, I’d like to hear about it. Find me on Bluesky or LinkedIn.

References

  1. Get started - Microsoft, Azure SQL Dev Hub. Labels the Azure SQL Database container as public preview, states that the image is public on Microsoft Container Registry with nothing to sign up for, and gives the image name mcr.microsoft.com/mssql/azure-sql-db-server. The tools section states that the container does not need an Azure subscription. ↩
  2. FAQ - Is it intended for production workloads? - Microsoft, Azure SQL Dev Hub. States that the container is intended for local development, automated testing and continuous integration, and that production applications belong on Azure SQL Database. ↩
  3. azure-sql-db-container-lab - Hannah Vernon. The lab described in this post, MIT licence, with a mirror at github.com/HannahVernon/azure-sql-db-container-lab. Not affiliated with Microsoft. The README’s Findings section records the tested image digest, build and results. ↩
  4. Get started - Host platforms - Microsoft, Azure SQL Dev Hub. Lists Windows 11 on x86_64 and ARM64 as supported through WSL2. ↩
  5. Get started - Container runtimes - Microsoft, Azure SQL Dev Hub. Lists the tested runtimes: Docker 24 or later, Podman 5.0 or later, Rancher Desktop 1.13 or later, containerd, and WSL containers (wslc, included with WSL on Windows). ↩
  6. Install Docker Engine on Debian - Docker Docs. Installation steps for Docker Engine on Debian, including the apt repository method. ↩
  7. Advanced settings configuration in WSL - systemd support - Microsoft Learn. Shows how to turn on systemd with systemd=true in the [boot] section of /etc/wsl.conf. ↩
  8. Linux post-installation steps for Docker Engine - Docker Docs. Covers running Docker without sudo through the docker group, with a warning that the group grants root-level privileges. ↩
  9. Get started - System resources - Microsoft, Azure SQL Dev Hub. Gives the minimum allocation for the container runtime: 2 CPU cores, 4 GB of memory and 10 GB of free disk. ↩
  10. cmdkey - Microsoft Learn. Documents /generic for generic credentials, and that cmdkey prompts for the password when /pass has no value. ↩
  11. about_PSReadLine - Command History - Microsoft Learn. States that PSReadLine keeps a history file of the commands you enter, under $Env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine on Windows, that the history can contain passwords, that lines containing password, asplaintext, token, apikey or secret aren’t written to the file, and that PSReadLine 2.2.0 and later use the parsed command line to look for sensitive data. ↩
  12. Get started - The container will not start, or will not accept connections - Microsoft, Azure SQL Dev Hub. Gives the sa password policy: 8 or more characters, with at least three of upper case, lower case, digits and symbols. ↩
  13. Advanced settings configuration in WSL - General WSL settings - Microsoft Learn. Documents instanceIdleTimeout: the milliseconds a distribution is idle before WSL shuts it down, default 15000. ↩
  14. Get started - Start the container - Microsoft, Azure SQL Dev Hub. The docker run and Compose examples, which pass the password in MSSQL_SA_PASSWORD. ↩
  15. docker inspect - Docker Docs. Documents returning low-level information on Docker objects, with --format examples that read fields under .Config. ↩
  16. Quickstart: Run SQL Server Linux container images with Docker - Microsoft Learn. For the SQL Server image, states that MSSQL_SA_PASSWORD is visible in ps -eax output and stored in an environment variable. ↩
  17. Manage secrets securely in Docker Compose - Docker Docs. States that injecting passwords as environment variables risks unintentional information exposure, and that Compose mounts each secret as a file under /run/secrets/. ↩
  18. sqlcmd utility - Microsoft Learn. Lists the SQLCMDPASSWORD environment variable as an alternative to -P for SQL authentication. ↩
  19. ALTER LOGIN (Transact-SQL) - Microsoft Learn. Syntax for changing a login’s password with WITH PASSWORD. ↩
  20. docker container run - Docker Docs. States that publishing a port without an IP address publishes it on all interfaces, where it is externally accessible. ↩
  21. Advanced settings configuration in WSL - Main WSL settings - Microsoft Learn. Documents localhostForwarding, default true, which makes ports bound to localhost in the WSL 2 VM connectable from the host, and networkingMode, default NAT. ↩
  22. TDS 8.0 - Microsoft Learn. Describes TrustServerCertificate=true as not recommended because the driver then doesn’t validate the server’s certificate, and links strict encryption to preventing a man-in-the-middle attack. ↩
  23. Get started - USE appdb fails with Msg 40508 - Microsoft, Azure SQL Dev Hub. States that Msg 40508 is expected and matches Azure SQL Database, and to select the database in the connection string. ↩
  24. Get started - Create your database - Microsoft, Azure SQL Dev Hub. Creates the database with IF DB_ID('appdb') IS NULL CREATE DATABASE appdb; on a master connection. ↩
  25. DB_ID (Transact-SQL) - Remarks - Microsoft Learn. States that in Azure SQL Database, DB_ID returns the ID of the current database only, and returns NULL for any other database name. ↩
  26. Fix the create-database check in container get started - microsoft/azure-sql-dev-hub pull request 58, GitHub. Replaces the DB_ID guard with a sys.databases check. ↩
  27. microsoft/microsoft-sql issue 91 - GitHub. Reports the DB_ID guard in the SQL agent skills, and wait loops that don’t exit when the guard fails. ↩
  28. FAQ - Will an application that works with the container work unchanged in Azure SQL Database? - Microsoft, Azure SQL Dev Hub. States that the container is not a replacement for validation in Azure, and to test against Azure SQL Database before production. ↩
  29. FAQ - Feature availability - Microsoft, Azure SQL Dev Hub. Lists Change Tracking among the capabilities not included in the container. ↩
  30. microsoft/azure-sql-dev-hub issue 59 - GitHub. Reports that Change Tracking works on the container although the FAQ lists it as not included. ↩
  31. Azure SQL trigger for Functions - Microsoft Learn. States that the Azure SQL trigger uses change tracking to monitor a table and run a function when a row is created, updated or deleted. ↩