Install SQL Server on Docker

Pull the SQL Server 2022 image and run the container with rootless Podman, choose the edition with MSSQL_PID, get a certificate with Certbot.

For these steps I use Podman rather than Docker on my Debian machine, to get a serviceless installation that does not need to run as root.

Pulling the SQL Server Docker image

The list of downloadable images is here.

You can pick the edition through the environment variables, with MSSQL_PID: for instance -e "MSSQL_PID=Developer" for the Developer edition. The sa password goes in MSSQL_SA_PASSWORD; the older SA_PASSWORD variable is deprecated. Replace <password> with a password that meets the SQL Server policy (at least eight characters, from three of the four sets: uppercase, lowercase, digits, symbols), otherwise the container stops at startup. The variables are listed in the Microsoft documentation.

podman pull mcr.microsoft.com/mssql/server:2022-latest

podman run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<password>" -e "MSSQL_PID=Developer" -p 1433:1433 --name sql_server_2022 -d mcr.microsoft.com/mssql/server:2022-latest

Check that the container is running:

podman ps

Getting an SSL certificate with Certbot

To encrypt connections with a trusted certificate, Certbot gets a Let’s Encrypt certificate for the server’s DNS name. In --standalone mode it opens port 80 on the machine itself, and that port must be reachable from the Internet. Replace sql.example.com with the name of your server.

sudo certbot certonly --standalone --preferred-challenges http -d sql.example.com

You then declare the certificate to SQL Server with mssql-conf (network.tlscert and network.tlskey): the procedure is in Encrypting connections to SQL Server on Linux.