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.

1. Install Docker

2. Pull the Official SQL Server Image

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.)

3. Run the SQL Server Container

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

4. Check Container Status

bash
docker ps

This lists all running containers. Confirm your container is active.

5. Connect to SQL Server Instance

Sample sqlcmd connection (from terminal):

bash
sqlcmd -S localhost -U sa -P YourStr0ngP@ssw0rd

6. Persist Your Data (Recommended for Production/Dev)

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.

7. Optional: Attach Existing Databases

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.

8. Stopping and Removing the Container

To stop:

bash
docker stop sql2025

To remove:

bash
docker rm sql2025

Data is saved, if you use mapped volumes as above.

9. Upgrade SQL Server in Container

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.