Deploying an MSSQL App
Introduction
Microsoft SQL Server (MSSQL) is a relational database widely used for transactional and analytics workloads. Deploying MSSQL with a Dockerfile on Klutch.sh gives you reproducible builds, managed secrets, and persistent storage for data files—all managed from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, sample connection code, and production tips.
Prerequisites
- A Klutch.sh account (create one)
- A GitHub repository containing your MSSQL Dockerfile/config (GitHub is the only supported git source)
- Docker familiarity
- Storage for database files and backups
For platform onboarding, see the Quick Start.
Architecture and ports
- MSSQL listens on TCP port
1433; set the internal container port to1433and choose TCP traffic in Klutch.sh. - Persistent storage is required for
/var/opt/mssqlto retain databases and logs. - Only expose the SQL port you need; restrict network access appropriately.
Repository layout
mssql/├── Dockerfile # Must be at repo root for auto-detection├── scripts/ # Optional init scripts├── README.md└── .env.example # Template only; no secretsKeep secrets out of Git; store them in Klutch.sh environment variables.
Installation (local) and starter commands
Test MSSQL locally before pushing to GitHub:
docker run --rm -p 1433:1433 \ -e ACCEPT_EULA=Y \ -e SA_PASSWORD="StrongPassw0rd!" \ -v $(pwd)/data:/var/opt/mssql \ mcr.microsoft.com/mssql/server:2022-latestOptional helper start.sh for portability and Nixpacks fallback:
#!/usr/bin/env bashset -euo pipefailexec /opt/mssql/bin/sqlservrMake it executable with chmod +x start.sh.
Dockerfile for MSSQL (production-ready)
Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI):
FROM mcr.microsoft.com/mssql/server:2022-latest
WORKDIR /app
# Copy optional init scriptsCOPY scripts /app/scripts
EXPOSE 1433CMD ["/opt/mssql/bin/sqlservr"]Notes:
- Pin the image tag for reproducible builds.
- Ensure
SA_PASSWORDmeets MSSQL complexity requirements.
Environment variables (Klutch.sh)
Set these in the Klutch.sh app settings (Secrets tab) before deploying:
PORT=1433ACCEPT_EULA=YSA_PASSWORD=<StrongPassw0rd!>MSSQL_PID=Developer(orStandard/Enterpriseif licensed)
If you deploy without the Dockerfile and need Nixpacks overrides:
NIXPACKS_BUILD_CMD="echo MSSQL uses prebuilt image"NIXPACKS_START_CMD=/opt/mssql/bin/sqlservrNIXPACKS_JDK_VERSION=17(not required for MSSQL itself, but listed for completeness)
Attach persistent volumes
In Klutch.sh storage settings, add mount paths and sizes (no names required):
/var/opt/mssql— required for database files and transaction logs.
Ensure this path is writable inside the container.
Deploy MSSQL on Klutch.sh (Dockerfile workflow)
- Push your repository (with the Dockerfile at the root) to GitHub.
- Open klutch.sh/app, create a project, and add an app.
- Connect the GitHub repository; Klutch.sh automatically detects the Dockerfile.
- Choose TCP traffic for MSSQL.
- Set the internal port to
1433. - Add the environment variables above (EULA, SA password, PID, and any
NIXPACKS_*overrides if you temporarily deploy without the Dockerfile). - Attach a persistent volume for
/var/opt/mssql, selecting a size that fits your data and log growth. - Deploy. Your MSSQL endpoint will be reachable at
example-app.klutch.sh:8000over TCP for clients.
Sample code (Node.js connection)
import sql from "mssql";
const config = { user: "sa", password: "StrongPassw0rd!", server: "example-app.klutch.sh", port: 8000, database: "master", options: { encrypt: false },};
const pool = await sql.connect(config);const result = await pool.request().query("SELECT name FROM sys.databases");console.log(result.recordset);await pool.close();Health checks and production tips
- Use a simple query (e.g.,
SELECT 1) via your monitoring agent for health checks. - Enforce strong passwords and rotate credentials; store them only in Klutch.sh secrets.
- Monitor disk usage on
/var/opt/mssqland resize volumes before they fill. - Pin image tags and apply updates intentionally.
- Configure backups externally; do not rely solely on container storage.
MSSQL on Klutch.sh combines reproducible Docker builds with managed secrets, durable volumes for data, and flexible TCP routing. With the Dockerfile at the repo root and port 1433 configured, you can run SQL Server reliably without extra YAML or workflow overhead.