---
title: "Deploy Microsoft SQL Server | (Just Updated) The One Whose Engine Actually Starts"
description: "SQL Server 2022 that actually starts, with backups that survive redeploys"
category: "Storage"
url: https://railway.com/deploy/microsoft-sql-server-or-just-updated-the
---

# Deploy Microsoft SQL Server | (Just Updated) The One Whose Engine Actually Starts

SQL Server 2022 that actually starts, with backups that survive redeploys

**[Deploy Microsoft SQL Server | (Just Updated) The One Whose Engine Actually Starts on Railway](https://railway.com/template/microsoft-sql-server-or-just-updated-the)**

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

- **Creator:** SuperSlowSloth
- **Category:** Storage

## Template content

### mssql

- **Image:** ghcr.io/bon5co/mssql-railway@sha256:ac88c6f742983825495515ae098cead6977d5fd4cff05f98ea55bc24e264e3fe

## Documentation

# Deploy and Host Microsoft SQL Server on Railway

Microsoft SQL Server is Microsoft's relational database engine: T-SQL, stored procedures,
transactions, full-text search and the tooling ecosystem around SSMS, Azure Data Studio and
the .NET / JDBC / ODBC drivers.

This template runs SQL Server 2022 on Railway with an engine that actually starts, a
generated `sa` password, a public TCP proxy, and a persistence design built around the one
platform limit that stops every other SQL Server listing from working.

## About Hosting Microsoft SQL Server

SQL Server is unusually hostile to a container platform, and the reason is the filesystem.

**A Railway volume reports a 16384-byte sector size, and SQL Server accepts at most 4096.**
Any data file placed on the volume is rejected outright:

```
Cannot use file '/var/opt/mssql/data/x.mdf', because it is on a volume with sector size 16384.
SQL Server supports a maximum sector size of 4096 bytes.
```

No configuration reaches that check — write-through, trace flag 3979 and trace flag 1800 were
each verified applied on a live deploy and the rejection is unchanged, because the check reads
the filesystem's reported sector size rather than the IO path.

The consequence is that mounting a volume at `/var/opt/mssql`, which is the layout every other
listing in this category uses, does not give you persistence. It gives you an engine that never
starts. On a live control deploy of a competing template, `sqlservr` crash-loops about once a
second with:

```
/opt/mssql/bin/sqlservr: Error: The system directory [/.system] could not be created.
File: LinuxDirectory.cpp:420 [Status: 0xC0000022 Access Denied errno = 0xD(13) Permission denied]
```

with zero occurrences of "ready for client connections" in the whole deploy log — while Railway
reports the deployment **SUCCESS**, because no listing in this category publishes a healthcheck.
A greenly-deployed database server whose engine died during startup is the normal state of this
category.

**This template takes the other route.** The data files stay on the container's own filesystem,
where the sector size is correct and the engine starts normally, and durability is provided by
a backup and restore cycle onto the volume:

- The engine first starts on a private port Railway does not route, restores the most recent
  backup of every user database, and replays the recorded SQL logins with their original SIDs
  and password hashes, so applications keep working without re-granting anything.
- Only then does it shut down and re-start on 1433, so the first connection the deploy ever
  accepts is against restored state.
- `BACKUP DATABASE ... TO DISK` runs on a schedule (`MSSQL_BACKUP_INTERVAL_MINUTES`, default 15)
  and once more on shutdown, so an ordinary redeploy loses nothing.

Measured on a live Railway redeploy: a seeded table row and a created login were both present
after the container was replaced.

The container also repairs the volume's root ownership, sizes the engine's CPU affinity from the
cgroup quota rather than the host's core count, and refuses to boot on an empty `sa` password.

## Why Deploy Microsoft SQL Server on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your
infrastructure so you don't have to deal with configuration, while allowing you to vertically
and horizontally scale it.

By deploying Microsoft SQL Server on Railway, you are one step closer to supporting a complete
full-stack application with minimal burden. Host your servers, databases, AI agents, and more on
Railway.

Compared with running it yourself, you get a managed volume, a generated credential, a public
endpoint and a scheduled backup cycle without touching a configuration file.

## Common Use Cases

- **A development or staging database for a .NET application** that targets SQL Server in
  production, reachable from your laptop over the TCP proxy.
- **Migrating or testing an existing SQL Server schema** — restore a `.bak`, run your migrations,
  point an ORM at it.
- **A backend database for an internal tool** that already speaks T-SQL, alongside the rest of
  your services on the same private network.

## Dependencies for Microsoft SQL Server

- SQL Server 2022 (provided by the image).
- A Railway volume, used for backups and login state.

### Deployment Dependencies

- Upstream image: [mcr.microsoft.com/mssql/server](https://hub.docker.com/_/microsoft-mssql-server),
  pinned by digest.
- Wrapper image and entrypoint:
  [bon5co/mssql-railway](https://github.com/bon5co/mssql-railway)
- SQL Server documentation:
  [learn.microsoft.com/sql](https://learn.microsoft.com/en-us/sql/sql-server/)

### Implementation Details

Connect from outside Railway with `SQLSERVER_URL`, and from another service in the same project
with `SQLSERVER_PRIVATE_URL`. `SQLSERVER_HOST`, `SQLSERVER_PORT`, `SQLSERVER_USER` and
`SQLSERVER_PASSWORD` are published separately for drivers that want the parts.

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

The image ships the **Developer** edition, which is free but licensed for development and test
use only. For production use, set `MSSQL_PID=Express` — free for production, with a 10 GB limit
per database and a lower memory ceiling — or supply your own licence key.

Backups live on the volume under `/data/backups` and are taken every
`MSSQL_BACKUP_INTERVAL_MINUTES` minutes and on shutdown. A crash between backups can lose up to
that interval of writes; lower the value if that matters more than the write cost.


## 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-or-just-updated-the
