Running Microsoft SQL Server in a Docker container on Linux is one of the fastest and cleanest ways to deploy a database instance for development, testing, or production environments. This guide walks you through the entire process from start to finish: removing conflicting installations, setting up the Docker container, and connecting to it remotely using SQL Server Management Studio (SSMS).

Step 1: Clean Up Native Installations (If Applicable)

If you previously attempted a native installation of SQL Server via apt, you should remove it to prevent port conflicts or service overlaps with Docker.

Remove Native Packages: Stop and Purge

Stop the native SQL Server service, purge the package, and clear the data directory:

sudo systemctl stop mssql-server
sudo apt-get purge -y mssql-server
sudo rm -rf /var/opt/mssql

Verification: Run systemctl status mssql-server and verify that the service no longer exists.

Step 2: Pull the SQL Server Docker Image

Microsoft maintains official container images for SQL Server on the Microsoft Container Registry (MCR).

Pull SQL Server 2022 Image: Docker Registry

Download the latest SQL Server 2022 container image to your Linux host:

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

Verification: Run sudo docker images to ensure the image is successfully downloaded and listed.

Step 3: Run the SQL Server Container

To run the container, you must supply environment variables accepting the End-User License Agreement (ACCEPT_EULA=Y) and setting a strong system administrator password (MSSQL_SA_PASSWORD).

Start the Container Instance: Container Deployment

Execute the following command to deploy and run the container in the background:

sudo docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStrongPassword123!" \
   -p 1433:1433 --name sql-server-container \
   -d mcr.microsoft.com/mssql/server:2022-latest

(Note: Replace YourStrongPassword123! with a password that meets complexity requirements, containing uppercase, lowercase, numbers, and/or special characters.)

Verification: Run sudo docker ps and confirm that sql-server-container is running and mapping port 1433.

Step 4: Configure Network Firewalls

For remote machines (such as your Windows client running SSMS) to communicate with your Linux Docker instance, port 1433 must be explicitly opened.

Open Ports in Cloud Security Groups: Cloud Networking

  • Cloud Providers (e.g., Azure/AWS): Navigate to your Virtual Machine's networking settings and add an Inbound Port Rule allowing TCP traffic on Port 1433.

  • Host Firewall (UFW): If UFW is active on your Linux instance, run:

sudo ufw allow 1433

Verification: Run sudo ufw status to confirm the port is allowed.

Step 5: Connect Using SQL Server Management Studio (SSMS) from Windows

Once your container is running and ports are open, you can manage your database remotely from a Windows machine using SSMS.

Connect to the Server: SSMS Setup

  1. Launch SQL Server Management Studio (SSMS) on your Windows machine.

  2. In the Connect to Server dialog box, fill out the parameters:

    • Server type: Database Engine

    • Server name: Your Linux VM's Public IP address (e.g., 142.30.50.65)

    • Authentication: SQL Server Authentication

    • Login: sa

    • Password: The strong password you set during the docker run command (YourStrongPassword123!).

    • Encrypt: Set this to Optional (to prevent strict handshake timeouts with raw Docker containers).

  3. Click Connect.

    Verification: Expand the Object Explorer tree view on the left; your server node should display successfully, allowing you to create tables and execute queries.