
Prerequisites
- Docker installed on your system
- Docker Compose installed
- At least 2GB of RAM available
Step 1: Create Project Directory
mkdir mssql-docker
cd mssql-docker
Step 2: Create docker-compose.yml
Create a docker-compose.yml
file with the following content:
version: '3.8'
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
container_name: mssql-server
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=YourStrong@Password123
- MSSQL_PID=Developer
ports:
- "1433:1433"
volumes:
- mssql-data:/var/opt/mssql
restart: unless-stopped
volumes:
mssql-data:
Step 3: Configure Environment Variables
Important: Change the SA_PASSWORD
to a strong password. The password must:
- Be at least 8 characters long
- Contain uppercase and lowercase letters
- Contain numbers
- Contain special characters
Step 4: Start the Container
docker-compose up -d
Step 5: Verify Installation
Check if the container is running:
docker-compose ps
View logs:
docker-compose logs -f mssql
Step 6: Connect to SQL Server
You can connect using any SQL Server client with these credentials:
- Host: localhost
- Port: 1433
- Username: sa
- Password: (your password from docker-compose.yml)
Useful Commands
Stop the container:
docker-compose down
Stop and remove data:
docker-compose down -v
Restart the container:
docker-compose restart