Skip to content

Instantly share code, notes, and snippets.

@belgattitude
Last active February 24, 2025 23:00
Show Gist options
  • Save belgattitude/9979e5501d72ffa90c9460597dee8dca to your computer and use it in GitHub Desktop.
Save belgattitude/9979e5501d72ffa90c9460597dee8dca to your computer and use it in GitHub Desktop.
Example of mssql/server:2022-CU16-ubuntu-22.04 docker compose with healthcheck

Docker mssql server

Features

  • Recent mssql server version (server:2022-CU16-ubuntu-22.04 with mysql-tools-18)
  • Healthcheck

Requirements

  • Docker engine > 2.7

Structure

.
└── docker
    │── .env.mssql.development
    └── compose.yml

Files

.env.mssql.development

# Linux timezone
TZ=Etc/UTC

# Mssql variables
# @link https://learn.microsoft.com/en-us/sql/relational-databases/collations/collation-and-unicode-support?view=sql-server-ver15#utf8
MSSQL_COLLATION=LATIN1_GENERAL_100_CI_AS_SC_UTF8
MSSQL_SA_PASSWORD=AStrongValidPassword10!

# Choose Mssql edition
# @link https://hub.docker.com/r/microsoft/mssql-server
MSSQL_PID=Developer
ACCEPT_EULA=Y

compose.yml

name: example-mssql

services:
  mssql:
    image: mcr.microsoft.com/mssql/server:2022-CU16-ubuntu-22.04
    # Only when docker is running as "root".
    cap_add: ['SYS_PTRACE']
    env_file:
      - .env.mssql.development
    ports:
      - "1433:1433"
    networks:
      - mssql-net
    volumes:
      - data:/var/opt/mssql:rw
    restart: no
    healthcheck:
      test: /opt/mssql-tools18/bin/sqlcmd -S localhost -C -U sa -P "$$MSSQL_SA_PASSWORD" -Q "SELECT 1" -b -o /dev/null
      interval: 1s
      timeout: 45s
      retries: 45
      start_period: 3s

volumes:
  data:

networks:
  mssql-net:
    driver: bridge
    # prevent issues with macos/x
    enable_ipv6: false

Usage

Locally

docker compose up 

With healthchecks (waiting)

docker compose up --wait

Within github actions

 - name: 🔼 Start MSSQL server
   run: docker compose -f docker/compose.yml up -d --wait

Notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment