✅ How to Configure and Customize SQL Server Linux Containers
SQL Server on Linux containers offers powerful flexibility for development, testing, and even some production setups. You can customize your container using:
- Environment variables
- Custom Dockerfiles
- Persistent storage
- Startup scripts
- Docker Compose or env‑files
This guide walks you through each of these approaches.
1. Create and Customize SQL Server Linux Containers
1.1 Build a Customized Container
You can create your own Dockerfile and add scripts, packages, or configuration steps.
Example from Microsoft documentation: the SQL Server process must remain the primary (right‑most) foreground process; otherwise, the container shuts down when other steps finish.
/usr/src/app/do-my-sql-commands.sh &
/opt/mssql/bin/sqlservr
If sqlservr is not last, the container exits immediately after your custom script finishes.
2. Configure Using Environment Variables
SQL Server on Linux exposes a comprehensive set of environment variables covering setup, memory, language, storage paths, HADR, SQL Agent, ports, and more.
Here are some of the most important:
| Variable | Purpose |
|---|---|
ACCEPT_EULA |
Required to accept license terms |
MSSQL_SA_PASSWORD |
Sets sa password (replaces deprecated SA_PASSWORD) |
MSSQL_PID |
Sets edition or product key |
MSSQL_COLLATION |
Default collation |
MSSQL_LCID |
Language locale |
MSSQL_MEMORY_LIMIT_MB |
Max memory |
MSSQL_TCP_PORT |
Listen port (default 1433) |
MSSQL_DATA_DIR / MSSQL_LOG_DIR
|
Custom data & log paths |
MSSQL_BACKUP_DIR |
Backup directory |
MSSQL_AGENT_ENABLED |
Enable SQL Agent (true/false) |
MSSQL_ENABLE_HADR |
Enable Availability Groups |
Example Container Run
docker run -e "ACCEPT_EULA=Y" \
-e "MSSQL_SA_PASSWORD=MyP@ssw0rd!" \
-e "MSSQL_AGENT_ENABLED=true" \
-e "MSSQL_TCP_PORT=1533" \
-p 1533:1533 \
--name sqlserver \
-d mcr.microsoft.com/mssql/server:2022-latest
3. Persisting Data (Critical!)
Container files are ephemeral. To retain your databases, use volumes.
SQL Server recommends mounting /var/opt/mssql, the location for data, logs, dumps, and configs.
Example:
docker run -e "ACCEPT_EULA=Y" \
-e "MSSQL_SA_PASSWORD=MyP@ssw0rd!" \
-v ~/sqlvolumes:/var/opt/mssql \
-p 1433:1433 \
--name sql1 \
-d mcr.microsoft.com/mssql/server:2022-latest
4. Using Docker Compose for Multi‑Container or Complex Configs
Docker Compose simplifies multi‑step setups (e.g., AOAG clusters). It passes environment variables, mounts volumes, and orchestrates replicated SQL Server containers.
Example docker-compose.yml:
services:
sql1:
image: mcr.microsoft.com/mssql/server:2022-latest
environment:
ACCEPT_EULA: "Y"
MSSQL_SA_PASSWORD: "MyP@ssw0rd!"
MSSQL_AGENT_ENABLED: "true"
ports:
- "1433:1433"
volumes:
- sql1data:/var/opt/mssql
volumes:
sql1data:
5. Using .env Files for Cleaner Configuration
Instead of piling up variables in Docker commands, store them in a file (example from Axial SQL).
config.env:
MSSQL_PID=Developer
ACCEPT_EULA=Y
MSSQL_AGENT_ENABLED=True
MSSQL_DATA_DIR=/var/opt/sqlserver/sqldata
MSSQL_LOG_DIR=/var/opt/sqlserver/sqllog
MSSQL_BACKUP_DIR=/var/opt/sqlserver/sqlbackups
Run with:
docker run --env-file config.env \
-e MSSQL_SA_PASSWORD=MyP@ssw0rd! \
-p 1433:1433 \
--name sqlcontainer1 \
-d mcr.microsoft.com/mssql/server:2019-latest
6. Copy Files In and Out of Containers
SQL Server containers support file copying (e.g., backups, scripts).
docker cp myscript.sql sql1:/tmp/myscript.sql
docker exec -it sql1 /opt/mssql-tools18/bin/sqlcmd \
-S localhost -U sa -P MyP@ssw0rd! -i /tmp/myscript.sql
7. Advanced Customization with Dockerfile
You can:
- Install extra tools
- Add startup scripts
- Change OS‑level settings
- Customize collation or locale via environment variables at build time
Example from SQL Server 2025 container customization: you can specify collation during container creation only.
-e "MSSQL_COLLATION=Latin1_General_BIN2"
8. Starting SQL Server 2025 Preview Containers
Microsoft’s official SQL Server 2025 preview image command:
docker run -e "ACCEPT_EULA=Y" \
-e "MSSQL_SA_PASSWORD=<password>" \
-e "MSSQL_PID=Evaluation" \
-p 1433:1433 \
--name sqlpreview \
--hostname sqlpreview \
-d mcr.microsoft.com/mssql/server:2025-latest
9. Additional Notes & Best Practices
Non‑root containers
SQL Server 2019+ containers run as non‑root for security.
Encryption‑first ODBC tooling
ODBC 18 enforces encryption by default when using sqlcmd inside containers.
Availability Groups in containers
You can build clusterless Always On AG setups using Docker Desktop + scripts.
✅ Summary
To configure and customize SQL Server Linux containers:
- Use environment variables for edition, passwords, ports, collation, memory, and SQL Agent.
- Use Dockerfiles to automate customizations.
- Use volumes to persist SQL data.
- Use copy commands or mount points for scripts and backups.
- Use Docker Compose or env files for multi‑container setups or cleaner configs.
- Consider SQL Server 2025 preview features and new image behaviors.
Ref: https://learn.microsoft.com/en-nz/sql/sql-server/?view=sql-server-ver16
Top comments (0)