Microsoft SQL Server - Docker Setup & Usage Guide
ℹ️ Introduction
This guide explains how to set up and access Microsoft SQL Server using Docker Compose. By default this stack uses the shared external Docker network so other containers can reach the database directly.
⚡🏃♂️ Quick Setup
- Make sure the external network exists (or create it)
docker network create --subnet=172.40.0.0/24 dev1-net
docker network ls
- Create and start the container stack
docker compose -f compose.yaml up -d --force-recreate --remove-orphans
- Verify the network
- Verify that both containers are on the same network:
docker network inspect dev1-net - Verify the SQL Server service from the host:
sqlcmd -S localhost,14330 -U sa -P DockerMssql123! -Q "SELECT name FROM sys.databases"
▶️ Usage
Default Credentials
- Server name inside Docker:
mssql - Server name from host:
localhost,14330 - Admin login:
sa - Admin password:
DockerMssql123! - Default database:
docker - App login:
docker - App password:
DockerUser123!
Access the Database from Another Container
When another Docker container is attached to the same external network, use these values:
DB_HOST=mssqlDB_PORT=1433DB_NAME=dockerDB_USER=dockerDB_PASSWORD=DockerUser123!
Example: Web Application Compose File
webapp:
build: ./webapp
environment:
DB_HOST: mssql
DB_PORT: 1433
DB_NAME: docker
DB_USER: docker
DB_PASSWORD: DockerUser123!
Access from Host or External Machine
Use the host port from compose.yaml:
DB_HOST=127.0.0.1
DB_PORT=14330
DB_NAME=docker
DB_USER=docker
DB_PASSWORD=DockerUser123!
HeidiSQL on Windows
If HeidiSQL shows a warning about SQLOLEDB and insecure TLS 1.0, that warning comes from the old Windows client provider, not from this Docker container.
Use this approach on the host:
- Install the current Microsoft OLE DB Driver for SQL Server on Windows.
- In HeidiSQL, avoid the legacy
SQLOLEDBprovider when connecting to this server. - Use the same host settings shown above:
localhost, port14330, databasedocker, userdockerorsa. - For local development, use encrypted connections with
TrustServerCertificate=Truewhen the client asks for certificate-related settings.
Example Connection Strings
Server=mssql,1433;Database=docker;User Id=docker;Password=DockerUser123!;TrustServerCertificate=True;
Server=localhost,14330;Database=docker;User Id=docker;Password=DockerUser123!;TrustServerCertificate=True;
Notes
- SQL Server requires a strong password. Change
MSSQL_SA_PASSWORDandMSSQL_PASSWORDin.envbefore using this stack outside local development. - The
mssql-initsidecar creates thedockerdatabase anddockerlogin the first time the stack starts.