This is the easiest way you can run SQL Server in a Docker Container
- You have to have a Linux installed with Docker CE (27.3.1) installed (https://www.hofsvang.no/?p=165)
- Make an .env file in directory ~/docker/sqlserver
SA_PASSWORD=testdb - Make a docker-compose.yaml file like this for persistent data in directory ~/docker/sqlserver
services:
db:
container_name: sqlserver-db-1
image: mcr.microsoft.com/mssql/server:2022-latest
restart: always
environment:
ACCEPT_EULA: "Y"
SA_PASSWORD: "${SA_PASSWORD}"
ports:
- '1433:1433'
expose:
- '1433'
volumes:
- data:/var/opt/mssql
volumes:
data:
- Start the container
cd ~/docker/sqlserver
docker compose up -d
docker logs -f --until=2s sqlserver-db-1
- How to enable SQL Agent
docker exec --user=root -ti sqlserver-db-1 /bin/bash
# /opt/mssql/bin/mssql-conf set sqlagent.enabled true
# exit
docker compose restart
Set memory limit for SQL Server to 2GB memory
docker exec -ti sqlserver-db-1 /bin/bash
$ /opt/mssql-tools18/bin/sqlcmd -Usa -C
EXEC sys.sp_configure N'show advanced options', N'1' RECONFIGURE WITH OVERRIDE
GO
EXEC sys.sp_configure N'max server memory (MB)', N'2048'
GO
RECONFIGURE WITH OVERRIDE
GO
EXEC sys.sp_configure N'show advanced options', N'0' RECONFIGURE WITH OVERRIDE
GO
exit
$ exit