Containerised Microsoft SQL Server With Grafana
A short example of using Grafana, Microsoft SQL Server, and Docker Compose
I recently set up Grafana with SQL Server at work and decided to document the process. This isn’t a very complex task, but there were a couple of edge cases I needed to lookup once or twice.
I created a repository plus a Docker Compose file for convenience. It is available here.
Provisioning Grafana #
Although I’ve used Grafana in a variety of contexts, this was the first time that I have used SQL Server with it (though I’ve used SQL Server itself more times than I can count).
apiVersion: 1
datasources: - name: MSSQL type: mssql url: localhost:1433 user: sa jsonData: database: ${MSSQL_DB_NAME} encrypt: 'false' secureJsonData: password: ${MSSQL_SA_PASSWORD}
Docker Compose #
This is the bulk of the configuration in the repository. It sets up containers, volumes, health checks, environment variables, and the exposed ports.
version: '3.8'
services: sql-server: image: mcr.microsoft.com/mssql/server:2022-latest environment: ACCEPT_EULA: 'Y' MSSQL_SA_PASSWORD: ${MSSQL_SA_PASSWORD} MSSQL_PID: 'Express' ports: - "1433:1433" volumes: - sql_data:/var/opt/mssql restart: always healthcheck: test: ["CMD-SHELL", "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${MSSQL_SA_PASSWORD} -Q 'SELECT 1' || exit 1"] interval: 10s retries: 10 start_period: 10s timeout: 3s
wait-for-sql-server: image: ghcr.io/flcdrg/wait-for-mssql:2.0.35 depends_on: - sql-server command: --server sql-server --username sa --password ${MSSQL_SA_PASSWORD} restart: "no"
grafana: image: grafana/grafana:11.0.0 ports: - "3000:3000" environment: GF_SECURITY_ADMIN_USER: ${GF_SECURITY_ADMIN_USER} GF_SECURITY_ADMIN_PASSWORD: ${GF_SECURITY_ADMIN_PASSWORD} GF_PLUGIN_GRAFANA_IMAGE_RENDERER_RENDERING_IGNORE_HTTPS_ERRORS: true MSSQL_DB_NAME: ${MSSQL_DB_NAME} depends_on: - wait-for-sql-server volumes: - grafana_data:/var/lib/grafana - grafana_logs:/var/log/grafana - grafana_config:/etc/grafana - ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources restart: always
volumes: grafana_data: grafana_logs: grafana_config: sql_data:
Environment Variables #
If you intend to clone and run this repository, as per the README
, you’ll need to create a .env
file and provide the following values. This is not a particularly elegant solution for a production system, but it works.
GF_SECURITY_ADMIN_USER=placeholderGF_SECURITY_ADMIN_PASSWORD=placeholderMSSQL_SA_PASSWORD=placeholderMSSQL_DB_NAME=placeholder