version: '3.8'

services:
  sqlserver:
    build:
      context: .
      dockerfile: sql-server/Dockerfile
    container_name: sql1
    ports:
      - "1433:1433"
    environment:
      - ACCEPT_EULA=Y
      - MSSQL_PID=Express
      - SA_PASSWORD=YourStrong@Passw0rd
    volumes:
      - sqlserver_data:/var/opt/mssql
    deploy:
      resources:
        limits:
          memory: 2G    # Minimum required for SQL Server
          cpus: '1.0'   # Limit to 1 CPU core
        reservations:
          memory: 2G    # Must reserve 2GB minimum for SQL Server to start
          cpus: '0.25'  # Reserve quarter of a CPU core  
    restart: unless-stopped
    healthcheck:
      test: /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$$SA_PASSWORD" -Q "SELECT 1" || exit 1
      interval: 10s
      timeout: 3s
      retries: 10
      start_period: 10s

volumes:
  sqlserver_data:
    driver: local