---
title: "Deploy Microsoft SQL Server 2022"
description: "Pinned SQL Server 2022 CU Developer, volume, TCP 1433, generated SA secret."
category: "Storage"
url: https://railway.com/deploy/microsoft-sql-server-2022
---

# Deploy Microsoft SQL Server 2022

Pinned SQL Server 2022 CU Developer, volume, TCP 1433, generated SA secret.

**[Deploy Microsoft SQL Server 2022 on Railway](https://railway.com/template/microsoft-sql-server-2022)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/microsoft-sql-server-2022/manifest.json

- **Creator:** leodev
- **Category:** Storage

## Template content

### MicrosoftSQL

- **Image:** mcr.microsoft.com/mssql/server:2022-CU26-ubuntu-22.04@sha256:ba4c8329f48fb8f02e1416be6a930ebfd71268caee78aa985f3af4315e457c89
- **Start command:** `/bin/bash -c 'test "${ACCEPT_EULA:?Set ACCEPT_EULA=Y only after accepting the Microsoft EULA}" = Y && : "${MSSQL_PID:?Choose a licensed edition explicitly; Developer is NONPRODUCTION}" && exec /opt/mssql/bin/sqlservr -T1800'`

## Documentation

# Deploy and Host Microsoft SQL Server 2022 on Railway

Pinned **SQL Server 2022 CU26 Developer** edition. Persistent data at `/var/opt/mssql`, public **TCP 1433**, and a generated `sa` password that meets SQL Server complexity rules.

This listing replaces rotting marketplace clones that still ship `mcr.microsoft.com/mssql/server:2022-latest` (or a GitHub Dockerfile `ARG TAG_NAME=2022-latest`) with no CU pin.

## About Hosting Microsoft SQL Server 2022 on Railway

Railway pulls the official Microsoft image `mcr.microsoft.com/mssql/server:2022-CU26-ubuntu-22.04` (not `:latest`). A volume is mounted at `/var/opt/mssql` so databases survive redeploys. A TCP proxy on application port **1433** exposes SSMS / Azure Data Studio / `sqlcmd` access. Private networking is used for other services in the same project.

The start command is `/opt/mssql/bin/sqlservr -T1800`. Trace flag 1800 is required on Railway volumes (4K sectors); without it SQL Server can stack-overflow after misaligned IO on `master.mdf`.

SQL Server on Linux wants about **2 GB RAM**. `MSSQL_MEMORY_LIMIT_MB=2048` caps the engine so it does not size itself against the host.

Developer edition includes Enterprise features and is licensed for development and test only, not production. `ACCEPT_EULA=Y` means you agree to [Microsoft’s SQL Server EULA](https://go.microsoft.com/fwlink/?LinkId=746388).

First boot can take 1–2 minutes. Wait for `SQL Server is ready for client connections` in the deploy logs.

## Common Use Cases

- App backends that speak TDS (Node `mssql`, .NET, JDBC, Go, Python) against a private `MSSQL_URL`
- Local SSMS / Azure Data Studio connected through the public TCP proxy
- Dev and CI databases that need a current 2022 CU instead of an unpinned `:latest` tag
- Lift-and-shift prototypes that already assume SQL Server, not Postgres/MySQL/Redis

## Dependencies for Microsoft SQL Server 2022 Hosting

- **Image:** `mcr.microsoft.com/mssql/server:2022-CU26-ubuntu-22.04`
- **Edition:** Developer (`MSSQL_PID=Developer`)
- **Volume:** `/var/opt/mssql`
- **Port:** `1433` (private + public TCP proxy)
- **Start command:** `/opt/mssql/bin/sqlservr -T1800`
- **EULA:** [SQL Server container EULA](https://go.microsoft.com/fwlink/?LinkId=746388)

### Deployment Dependencies

#### Generated (do not set on deploy)

| Variable | What it is |
| --- | --- |
| `MSSQL_SA_PASSWORD` | `sa` password. Generated as `Aa1!${{secret(32, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")}}` so it always meets SQL Server complexity (upper, lower, digit, symbol, 8+ chars) without `@`/`:` breaking connection URLs. |

#### Required / fixed

| Variable | Default | Notes |
| --- | --- | --- |
| `ACCEPT_EULA` | `Y` | Required. Confirms the Microsoft EULA. |
| `MSSQL_PID` | `Developer` | Edition or product key. |
| `MSSQL_USERNAME` | `sa` | Built-in sysadmin. Cannot be renamed. |
| `MSSQL_TCP_PORT` | `1433` | Private listen port. |
| `MSSQL_MEMORY_LIMIT_MB` | `2048` | Caps SQL Server memory. |
| `RAILWAY_RUN_UID` | `0` | Lets the volume at `/var/opt/mssql` be writable. |
| `RAILWAY_SHM_SIZE_BYTES` | `268435456` | 256 MB `/dev/shm`. |

#### Private and public hosts

Other Railway services should use the **private** URL. SSMS / Azure Data Studio / local tools use the **public** TCP proxy.

| Variable | Value | Use |
| --- | --- | --- |
| `MSSQL_SERVER` | `${{RAILWAY_PRIVATE_DOMAIN}}` | Private hostname |
| `MSSQL_TCP_PORT` | `1433` | Private port |
| `MSSQL_SERVER_PUBLIC` | `${{RAILWAY_TCP_PROXY_DOMAIN}}` | Public TCP proxy hostname |
| `MSSQL_TCP_PORT_PUBLIC` | `${{RAILWAY_TCP_PROXY_PORT}}` | Public TCP proxy port |
| `MSSQL_URL` | `sqlserver://${{MSSQL_USERNAME}}:${{MSSQL_SA_PASSWORD}}@${{MSSQL_SERVER}}:${{MSSQL_TCP_PORT}}` | Private connection URL |
| `MSSQL_URL_PUBLIC` | `sqlserver://${{MSSQL_USERNAME}}:${{MSSQL_SA_PASSWORD}}@${{MSSQL_SERVER_PUBLIC}}:${{MSSQL_TCP_PORT_PUBLIC}}` | Public connection URL |

From another service in the same project:

```
${{MicrosoftSQL.MSSQL_URL}}
```

Drivers that need Encrypt (ADO.NET, recent `mssql` Node, JDBC):

```
Server=${{MicrosoftSQL.MSSQL_SERVER}},1433;User Id=sa;Password=${{MicrosoftSQL.MSSQL_SA_PASSWORD}};Encrypt=True;TrustServerCertificate=True
```

Public / off-Railway clients use `MSSQL_SERVER_PUBLIC` and `MSSQL_TCP_PORT_PUBLIC` instead.

### How to log in

1. Open the **MicrosoftSQL** service → **Variables**
2. Copy `MSSQL_SA_PASSWORD`
3. **Private (same Railway project):** host `MSSQL_SERVER`, port `1433`, user `sa`
4. **Public (SSMS, Azure Data Studio, local app):** host `MSSQL_SERVER_PUBLIC`, port `MSSQL_TCP_PORT_PUBLIC`, user `sa`
5. Enable encrypt + trust server certificate if the client requires TLS

`sqlcmd` example (public proxy):

```bash
sqlcmd -S "$MSSQL_SERVER_PUBLIC,$MSSQL_TCP_PORT_PUBLIC" -U sa -P "$MSSQL_SA_PASSWORD" -C -Q "SELECT @@VERSION"
```

## Why Deploy Microsoft SQL Server 2022 on Railway

Railway handles the image pull, volume, private DNS, and TCP proxy. This template is healthier than rotting marketplace clones because it:

- **Pins a CU tag** (`2022-CU26-ubuntu-22.04`), not `:latest` / `2022-latest`
- **Mounts a volume** at `/var/opt/mssql` so data survives deploys
- **Starts with trace flag 1800** so Railway 4K volumes do not stack-overflow on misaligned IO
- **Generates an SA secret** that satisfies SQL Server password complexity
- **Exposes TCP 1433** and documents private + public host/URL variables
- **Sets Developer edition + EULA** explicitly (`MSSQL_PID`, `ACCEPT_EULA=Y`)
- **Caps memory** with `MSSQL_MEMORY_LIMIT_MB=2048`

Official Railway Postgres / MySQL / Redis templates are already healthy. This listing is MSSQL only.

By setting `ACCEPT_EULA=Y` you accept the [SQL Server container EULA](https://go.microsoft.com/fwlink/?LinkId=746388). Developer edition is not licensed for production.


## Similar templates

- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.
- [Redis](https://railway.com/deploy/redis-1) — Self Host Latest Redis with Railway
- [EasyImg](https://railway.com/deploy/easyimg) — Simple self-hostable Nuxt.js personal image hosting system.

Open this page in a browser: https://railway.com/deploy/microsoft-sql-server-2022
