In this article we will learn about the Running Microsoft SQL Server in Docker | VS Code MSSQL Extension. Setting up a Microsoft SQL Server instance used to be a time-consuming operation that involved a complete installation and system-level configuration. However, thanks to Docker, we can now launch a fully functional SQL Server instance in minutes, without damaging our system environment. Please read my previous article on How to run ASP.Net Core Web Application in Docker Container.
In this guide, weโll walk through how to:
- Run SQL Server in Docker (cross-platform),
- Connect to it using the VS Code MSSQL Extension, and
- Perform basic operations inside the lightweight development setup.
Docker containers provide an isolated and consistent environment for PostgreSQL, which is refreshing. Say goodbye to conflicts and hello to consistency at various phases of development and deployment. It’s like having a dependable, well-behaved buddy for your database requirements.
To install SQL Server in Docker, you can follow these general steps. Please note that the commands and steps are based on Windows. These instructions assume you have Docker installed on your machine.
Pull the SQL Server Docker Image:
Open a terminal or command prompt and run the following command to pull the SQL Server Docker image from the official Microsoft repository:
docker pull mcr.microsoft.com/mssql/server

Run a SQL Server Container
Weโll need Docker Desktop installed and running. Then, run the following command to pull and start a SQL Server container. Use the following command to run a SQL Server container. Replaceย [PASSWORD]
ย with a strong password for theย SA
ย (System Administrator) account. You can also customize other parameters like the container name, port, and environment variables:
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD={YourPasswordGoesHere}" -p 1433:1433 --name sql_server -v sql_data:/var/opt/mssql -d mcr.microsoft.com/mssql/server
ACCEPT_EULA=Y
: Accepts Microsoftโs license agreement.SA_PASSWORD
: The strong password for thesa
(system admin) user.-p 1433:1433
: Exposes port 1433 to connect from host.--name sqlserver
: Container name.-d
: Detached mode (runs in background).

Connect to SQL Server:
Once the container is running, you can connect to SQL Server using a SQL Server client or tools like SQL Server Management Studio (SSMS) or Azure Data Studio. Connect to the server using the following details:
- Server:ย
localhost,1433
- Username:ย
sa
- Password: Here I have set
Admin@123
Here, I’m using VS Code Extension to connect the SQL Server that is running in docker.
Install the VS Code MSSQL Extension
Open Visual Studio Code and install the “SQL Server (mssql)” extension by Microsoft:
- Go to Extensions (Ctrl+Shift+X)
- Search for:
mssql
- Install the extension
This extension allows you to connect, run SQL queries, and manage databases โ all from within VS Code.

Connect to SQL Server from VS Code
- Open Command Palette (
Ctrl+Shift+P
orF1
) - Search:
MS SQL: Connect
- Enter connection details:
- Server:
localhost
- Port:
1433
- User:
sa
- Password:
Your_password123
- Database: Leave blank to connect to default (
master
)
- Server:

After clicking connect we would successfully connect the SQL Server that is running in docker.
Basic SQL Operations
Create a new file like demo.sql
and start with basic queries:
CREATE DATABASE DemoDB;
GO
USE DemoDB;
GO
CREATE TABLE Employees (
Id INT PRIMARY KEY IDENTITY,
Name NVARCHAR(50),
Role NVARCHAR(50)
);
GO
INSERT INTO Employees (Name, Role)
VALUES ('Alice', 'Developer'), ('Bob', 'DBA');
GO
SELECT * FROM Employees;

- If you want to stop the container, use the following command
docker stop sql_server
- To remove the container (after stopping it), use
docker rm sql_server
- If you need to start the container again, use:
docker start sql_server
Keep in mind that this is a basic setup, and you may wish to investigate more advanced settings based on your unique needs, such as mounting disks for persistent data storage and specifying extra environment variables. Always consult the official Microsoft documentation for the most up-to-date information and best practices.
Latest Articles
- Running Microsoft SQL Server in Docker | VS Code MSSQL Extension
- Building Real-Time Messaging with Kafka and .NET Core
- .NET 8 Authentication with Identity in a Web API using Bearer Tokens and Cookies
- How to convert Text To Speech With Azure Cognitive Services using Angular and .Net Core
- CRUD operation using the repository pattern with .Net 8, Ef-Core, and MySQL
- How to use Response Compression in .NET Core
- How to migrate .Net Core 7 to .Net Core 8
- How to Integrate GraphQL in .Net Core
- Upload Download and Delete files in Azure Blob Storage using ASP.NET Core and Angular
- How to upload files to Azure Blob Storage using Asp.Net Core Web API
- How to store app secrets in ASP.NET Core using Secret Manager
- Logging into Azure App Service with ASP.Net Core
- Integrate Paging in ASP.Net Core Web API- Beginner’s Guide
- Create CRUD Operation using ReactJs and ASP.Net Core API- Starter Template
- How to use Policy-based Authorization using JWT in .Net Core 7 and Angular
Conclusion
In this article we discussed about theย Running Microsoft SQL Server in Docker | VS Code MSSQL Extension. Setting up a Microsoft SQL Server instance used to be a time-consuming operation that involved a complete installation and system-level configuration.
Leave behind your valuable queries and suggestions in the comment section below. Also, if you think this article helps you, do not forget to share this with your developer community. Happy Coding ๐
SUPPORT ME
