Deploy Microsoft SQL Server | Enterprise Database on Railway
Self-host Microsoft SQL Server. Persistent storage, TCP proxy, SSMS-ready
MS Sql Server
Just deployed
/var/opt/mssql

Deploy and Host Microsoft SQL Server on Railway
Deploy Microsoft SQL Server 2022 on Railway with persistent storage, TCP proxy access, and zero infrastructure management. Self-host SQL Server in minutes using the official Microsoft Docker image (mcr.microsoft.com/mssql/server:2022-latest) with a Railway volume mounted at /var/opt/mssql for durable database storage across restarts and redeployments.
This Railway template pre-configures the SQL Server Developer edition with persistent volumes, secure SA credentials, and external TCP proxy connectivity. Connect from SQL Server Management Studio (SSMS), Azure Data Studio, or any application backend over the public internet.
Getting Started with Microsoft SQL Server on Railway
After deploying, Railway provisions a TCP proxy endpoint for external access. Find your connection details in the Railway dashboard under the service's variables: RAILWAY_TCP_PROXY_DOMAIN and RAILWAY_TCP_PROXY_PORT. The SA password is set as MSSQL_SA_PASSWORD — copy it from the dashboard.
Connect using sqlcmd, SSMS, or Azure Data Studio:
sqlcmd -S , -U sa -P ''
For application connections within Railway, use the private domain for lower latency:
Server=mssql.railway.internal,1433;User Id=sa;Password=;
Create your first database and start working:
CREATE DATABASE myapp;
GO
USE myapp;
CREATE TABLE users (id INT PRIMARY KEY IDENTITY, name NVARCHAR(100), email NVARCHAR(255));
GO
About Hosting Microsoft SQL Server
Microsoft SQL Server is a relational database management system built for enterprise workloads, business intelligence, and mission-critical applications. SQL Server 2022 on Linux brings the full T-SQL engine to Docker containers.
- Full T-SQL support — stored procedures, triggers, views, CTEs, window functions, and JSON/XML handling
- Built-in security — transparent data encryption (TDE), row-level security, dynamic data masking, and Always Encrypted
- Advanced query processing — intelligent query processing, columnstore indexes, in-memory OLTP
- SQL Server Agent — schedule and automate jobs, maintenance plans, and alerts
- Full-text search — built-in linguistic search across text columns
- High availability — Always On availability groups and log shipping support
- .NET ecosystem integration — native support for Entity Framework, ADO.NET, and ASP.NET applications
Why Deploy Microsoft SQL Server on Railway
Railway eliminates the operational overhead of managing SQL Server infrastructure:
- One-click deployment with persistent volumes — no manual Docker or VM setup
- TCP proxy for secure external access from SSMS, Azure Data Studio, or any client
- Private networking for low-latency service-to-service connections within Railway
- Automatic container restarts and health monitoring
- Scale resources on demand without re-provisioning
Common Use Cases for Self-Hosted SQL Server
- Backend database for .NET applications — ASP.NET Core, Blazor, and Entity Framework projects using SQL Server as the primary datastore
- Business intelligence and reporting — SQL Server Reporting Services (SSRS) and Analysis Services workloads with T-SQL analytical queries
- Legacy application migration — lift-and-shift Windows-based SQL Server workloads to containerized Railway deployments
- Development and staging environments — spin up isolated SQL Server instances for CI/CD pipelines and feature branch testing
Dependencies for Microsoft SQL Server on Railway
- Microsoft SQL Server —
mcr.microsoft.com/mssql/server:2022-latest(official Microsoft image, Ubuntu 22.04 based)
Environment Variables Reference for SQL Server on Railway
| Variable | Description | Required |
|---|---|---|
ACCEPT_EULA | Accept Microsoft EULA (Y) | Yes |
MSSQL_SA_PASSWORD | SA account password (8+ chars, mixed case/numbers/symbols) | Yes |
MSSQL_PID | Edition: Developer, Express, Standard, Enterprise | No (defaults to Developer) |
MSSQL_TCP_PORT | TCP listen port | No (defaults to 1433) |
MSSQL_AGENT_ENABLED | Enable SQL Server Agent (true/false) | No |
MSSQL_COLLATION | Default server collation | No |
MSSQL_MEMORY_LIMIT_MB | Max memory in MB | No (defaults to 80% of RAM) |
Deployment Dependencies
- Runtime: Linux container (Ubuntu 22.04)
- Docker Hub: microsoft/mssql-server
- GitHub: microsoft/mssql-docker
- Docs: SQL Server on Linux
Hardware Requirements for Self-Hosting Microsoft SQL Server
| Resource | Minimum | Recommended |
|---|---|---|
| CPU | 2 cores (x86-64) | 4+ cores |
| RAM | 2 GB | 4 GB+ |
| Storage | 2 GB | 10 GB+ (depends on data volume) |
| Runtime | Docker (Linux containers) | Docker with persistent volumes |
SQL Server is memory-intensive — it caches data pages in a buffer pool sized to 80% of available RAM by default. Use MSSQL_MEMORY_LIMIT_MB to cap memory usage when sharing resources with other services.
Self-Hosting Microsoft SQL Server with Docker
Run SQL Server locally with Docker in under a minute:
docker run -d \
--name mssql \
-e "ACCEPT_EULA=Y" \
-e "MSSQL_SA_PASSWORD=YourStr0ng!Pass" \
-e "MSSQL_PID=Developer" \
-p 1433:1433 \
-v mssql_data:/var/opt/mssql \
mcr.microsoft.com/mssql/server:2022-latest
Or with docker-compose.yml:
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
environment:
ACCEPT_EULA: "Y"
MSSQL_SA_PASSWORD: "YourStr0ng!Pass"
MSSQL_PID: "Developer"
ports:
- "1433:1433"
volumes:
- mssql_data:/var/opt/mssql
volumes:
mssql_data:
Connect with sqlcmd after startup:
sqlcmd -S localhost,1433 -U sa -P 'YourStr0ng!Pass'
How Much Does Microsoft SQL Server Cost to Self-Host?
SQL Server Developer and Express editions are free. Developer includes all Enterprise features but is licensed for development and testing only. Express is free for production but limited to 10 GB per database, 1 GB RAM, and 4 CPU cores. Standard edition starts at ~$3,586 per 2-core pack; Enterprise at ~$13,748 per 2-core pack. On Railway, you pay only for infrastructure (compute, storage, bandwidth) — no database licensing fees when using Developer or Express editions.
Microsoft SQL Server vs PostgreSQL
| Feature | SQL Server 2022 | PostgreSQL 17 |
|---|---|---|
| License | Proprietary (free Dev/Express tiers) | Open source (PostgreSQL License) |
| T-SQL / PL/pgSQL | T-SQL (native) | PL/pgSQL |
| .NET integration | Native (Entity Framework, ADO.NET) | Supported via Npgsql |
| JSON support | Yes (OPENJSON, FOR JSON) | Yes (JSONB, native operators) |
| Full-text search | Built-in | Built-in (tsvector) |
| Replication | Always On, log shipping | Streaming, logical |
| Windows auth | Yes (AD/Kerberos) | Limited GSSAPI |
| GUI tools | SSMS, Azure Data Studio | pgAdmin, DBeaver |
SQL Server is the natural choice for .NET-heavy stacks, Windows-ecosystem shops, and teams already invested in Microsoft tooling. PostgreSQL excels in cross-platform flexibility and has no licensing cost at any scale.
FAQ
What is Microsoft SQL Server and why self-host it? Microsoft SQL Server is a relational database management system supporting T-SQL, stored procedures, full-text search, and enterprise security features. Self-hosting gives you full control over data residency, configuration, and eliminates per-seat licensing costs with the free Developer or Express editions.
What does this Railway template deploy?
This template deploys a single SQL Server 2022 container using the official Microsoft Docker image (mcr.microsoft.com/mssql/server:2022-latest) with a persistent volume at /var/opt/mssql and a TCP proxy for external client connections on port 1433.
Why is a persistent volume included in this SQL Server template?
The volume at /var/opt/mssql stores all database files (.mdf, .ldf), the master database, error logs, and SQL Server configuration. Without it, all data would be lost on container restart or redeployment.
How do I connect to self-hosted SQL Server on Railway from SSMS?
Open SSMS and enter , as the server name (note the comma, not colon). Use SQL Server Authentication with username sa and the MSSQL_SA_PASSWORD from your Railway dashboard.
Can I run SQL Server Express edition on Railway instead of Developer?
Yes — set MSSQL_PID=Express in your environment variables. Express is free for production use but limited to 10 GB per database, 1 GB memory, and 4 CPU cores. Developer edition has no feature limits but is licensed for non-production use only.
How do I back up a SQL Server database on Railway?
Use T-SQL BACKUP DATABASE to write backups to the persistent volume, then download via railway shell or docker cp. Example: BACKUP DATABASE myapp TO DISK = '/var/opt/mssql/backup/myapp.bak'.
Template Content
MS Sql Server
mcr.microsoft.com/mssql/server:2022-latest