How to Install Microsoft SQL Server on Docker
Docker SQL Server MSSQL Linux Database DevOps Beginner Guide

How to Install Microsoft SQL Server on Docker

February 28, 2026 10 min read

A complete beginner's guide to running Microsoft SQL Server on Linux using Docker. Every command explained step by step — from installation to creating your first database and connecting with a GUI tool.

Introduction

Microsoft SQL Server is one of the most popular database systems in the world — used by businesses of all sizes to store and manage data. The great news is you don't need a Windows server or an expensive license to run it. You can run it for free on your Linux server using Docker in just a few minutes.

This guide walks you through every single step, with plain English explanations of every command.

What You'll Need

Key Terms Explained

TermWhat it means
SQL ServerMicrosoft's database management system — used to store, retrieve, and manage data
MSSQLShort for Microsoft SQL Server
DatabaseAn organized collection of data stored in tables (like spreadsheets)
TableA structured set of data organized into rows and columns — like an Excel sheet
SA"System Administrator" — the built-in admin account in SQL Server with full control
Port 1433The default network port that SQL Server listens on for connections
sqlcmdMicrosoft's official command line tool for running SQL commands
EULA"End User License Agreement" — the terms of use you must accept to use the software
PID"Product ID" — tells SQL Server which edition to run (Express, Developer, etc.)
Docker VolumeA storage area managed by Docker that persists your data even if the container is deleted
chown"Change Owner" — a Linux command to change who owns a file or folder

SQL Server Editions (Free Options)

You don't need to pay anything to follow this guide. Here are the free editions:

EditionBest ForLimits
ExpressSmall apps, learning10GB database size limit
DeveloperDevelopment and testingFull features, not for production use

For this guide we'll use Express. Change it to Developer if you need full features for testing.

Step 1: Connect to Your Server via SSH

Open your terminal and connect to your server:

ssh root@your-server-ip

Breaking this down:

Type your password when prompted and press Enter. You won't see the password as you type — that's normal.

Step 2: Create a Folder for SQL Server

Keep things organized by creating a dedicated folder:

mkdir ~/mssql && cd ~/mssql

Step 3: Fix Folder Permissions

SQL Server 2022 runs as a non-root user inside the container (user ID 10001). We need to create the data folder and give it the correct ownership so SQL Server can write to it:

mkdir -p ./mssql-data
sudo chown -R 10001:10001 ./mssql-data

Breaking this down:

Why is this needed? SQL Server 2022 changed its default behavior to run as a non-root user for security reasons. If the data folder is owned by root, SQL Server can't write to it and will crash with a "Permission Denied" error.

Step 4: Create the Docker Compose File

nano docker-compose.yml

nano opens a terminal text editor. Type or paste the following:

services:
  mssql:
    image: mcr.microsoft.com/mssql/server:2022-latest
    restart: unless-stopped
    user: root
    ports:
      - "1433:1433"
    environment:
      - ACCEPT_EULA=Y
      - SA_PASSWORD=YourStrongPassword123!
      - MSSQL_PID=Express
    volumes:
      - mssql-data:/var/opt/mssql

volumes:
  mssql-data:

Breaking this down:

Password Requirements: SQL Server enforces strong passwords. Your password must have at least 8 characters and include all of: an uppercase letter, a lowercase letter, a number, and a special character (like !, @, #). SQL Server will refuse to start if the password is too weak.

Save and exit nano: Press Ctrl + X, then Y to confirm, then Enter to keep the filename.

Step 5: Start SQL Server

docker compose up -d

SQL Server takes about 30 seconds to fully initialize. Give it a moment before the next step.

Step 6: Verify It's Running

Check the container is up:

docker ps

You should see a container called mssql-mssql-1 with status Up.

Then check the logs to confirm SQL Server started successfully:

docker compose logs

Look for this line:

SQL Server is now ready for client connections.

If you see it — SQL Server is running!

Step 7: Open the Firewall Port

sudo ufw allow 1433

Cloud server users (AWS, DigitalOcean, Linode, etc.): You also need to open port 1433 in your cloud provider's dashboard under "Security Groups" or "Firewall" settings. This is a separate firewall from the Linux one — both need to be configured.

Step 8: Test the Connection from Inside the Container

Let's verify SQL Server is working by connecting to it directly:

docker exec -it mssql-mssql-1 /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'YourStrongPassword123!' -No

Breaking this down:

You'll see a 1> prompt — you're connected! Run a quick test:

SELECT @@VERSION
GO

Type exit to disconnect.

Step 9: Create Your First Database

Still inside sqlcmd (or reconnect using the command from Step 8), run these SQL commands:

-- Create a new database
CREATE DATABASE myapp;
GO

-- Switch to using it
USE myapp;
GO

-- Create a users table
CREATE TABLE users (
    id INT PRIMARY KEY IDENTITY,
    name NVARCHAR(100),
    email NVARCHAR(100),
    created_at DATETIME DEFAULT GETDATE()
);
GO

-- Insert a test record
INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com');
GO

-- Read the data back
SELECT * FROM users;
GO

Breaking this down:

Step 10: Connect Using a GUI Tool (Recommended)

The command line is useful but a visual tool makes working with databases much easier. Azure Data Studio is Microsoft's free, cross-platform database GUI.

Download Azure Data Studio: azure.microsoft.com/products/data-studio

Connection details:

Alternatively, DBeaver is another free GUI that works great with SQL Server and many other databases: dbeaver.io

Troubleshooting Common Issues

Error: Permission Denied / .system could not be created

This is a folder permissions issue. Run:

docker compose down
mkdir -p ./mssql-data
sudo chown -R 10001:10001 ./mssql-data
docker compose up -d

Error: The provided PID is invalid

Your MSSQL_PID value is wrong. Make sure it's exactly Express or Developer — no extra characters, correct capitalization.

Error: Password validation failed

Your SA_PASSWORD doesn't meet the requirements. It must include uppercase, lowercase, a number, and a special character.

Can't connect from outside the server

Container name not found

Run docker ps and copy the exact container name shown — it may differ slightly.

Connection refused from GUI tool

Make sure "Trust server certificate" is enabled in your connection settings.

Useful Commands Reference

# Start SQL Server
cd ~/mssql && docker compose up -d

# Stop SQL Server
cd ~/mssql && docker compose down

# Restart SQL Server
cd ~/mssql && docker compose restart

# View logs
cd ~/mssql && docker compose logs

# Connect via terminal
docker exec -it mssql-mssql-1 /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'YourPassword' -No

# Check running containers
docker ps

# Check firewall status
sudo ufw status

What's Next?

Now that SQL Server is running, here are some things you can explore:

Summary

Here's the full process in a nutshell:

  1. Connect via SSH: ssh root@your-ip
  2. Create the project folder: mkdir ~/mssql && cd ~/mssql
  3. Fix folder permissions with chown
  4. Write your docker-compose.yml with your SA password and edition
  5. Launch: docker compose up -d
  6. Confirm it's ready in the logs
  7. Open port 1433 in the firewall
  8. Connect with sqlcmd and run a test query
  9. Create a database and table
  10. Connect using Azure Data Studio or DBeaver

You now have Microsoft SQL Server running on your Linux server inside Docker — completely free and ready to use!

Share this article
All Posts
Get In Touch Portfolio