Deploying SQL Server in a Docker container is a fast, portable way to get a reliable database environment for development or testing. Here’s a simple workflow to run SQL Server in Docker on your system.
Open your terminal/command prompt and run:
bash docker pull mcr.microsoft.com/mssql/server:2025-latest
(Replace 2025-latest with the actual tag for your desired SQL Server version.)
Start a new container with required environment variables:
bash docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=YourStr0ngP@ssw0rd" \ -p 1433:1433 --name sql2025 -d mcr.microsoft.com/mssql/server:2025-latest
ACCEPT_EULA=Y: Accepts the license.SA_PASSWORD: Sets the system administrator (SA) password.-p 1433:1433: Maps container port 1433 (SQL default) to host port 1433.--name sql2025: Names your container.bash docker ps
This lists all running containers. Confirm your container is active.
sqlcmd to connect.localhost, Port: 1433, User: sa, Password: the one you set above.Sample sqlcmd connection (from terminal):
bash sqlcmd -S localhost -U sa -P YourStr0ngP@ssw0rd
Use host directory or named volumes so your databases survive container shutdowns.
Example:
bash docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=YourStr0ngP@ssw0rd" \ -p 1433:1433 --name sql2025 \ -v /path/on/host/sql_data:/var/opt/mssql \ -d mcr.microsoft.com/mssql/server:2025-latest
This maps /path/on/host/sql_data to SQL Server’s data directory in the container.
Copy your .mdf (data) and .ldf (log) files into the mapped data directory. Attach them in SSMS or via T-SQL in a connected session.
To stop:
bash docker stop sql2025
To remove:
bash docker rm sql2025
Data is saved, if you use mapped volumes as above.
docker pull mcr.microsoft.com/mssql/server:<new_tag>Now you have a working SQL Server instance in Docker—ideal for agile development, easy testing, and rapid prototyping!
Need expert help identifying performance bottlenecks in your database? Contact NexaSQL today for a comprehensive performance audit and optimization plan.