Skip to content

Instantly share code, notes, and snippets.

@polynomialherder
Last active January 24, 2024 19:21
Show Gist options
  • Save polynomialherder/b86d94b99ce386ac851a774f89961762 to your computer and use it in GitHub Desktop.
Save polynomialherder/b86d94b99ce386ac851a774f89961762 to your computer and use it in GitHub Desktop.
Dockerfile for running SQL Server with SQL Agent enabled
# Usage:
# Ensure Docker daemon is running, then run from the same directory as this Dockerfile:
#
# docker build -t my-mssql-server .
# docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Yourstr0ngp@ssword' -p 1433:1433 --name sql1 -d my-mssql-server
#
# This builds the image. Then execute the following SQL on the server in SSMS to enable SQL Agent:
#
# EXEC sp_configure 'show advanced options', 1;
# EXEC sp_configure 'Agent XPs', 1;
# RECONFIGURE;
#
# Data in this database won't be persisted; see Microsoft's quickstart documentation below for guidance on how to
# persist data between sessions (also: how to generate dumps, query using sqlcmd, etc)
#
# This Dockerfile is based on Microsoft's FTS example in the mssql-docker repository
# https://github.com/microsoft/mssql-docker/blob/80e2a51d0eb1693f2de014fb26d4a414f5a5add5/linux/preview/examples/mssql-agent-fts-ha-tools/Dockerfile
# See also Microsoft's own quickstart guide:
# https://archive.is/gOPLa
#
# TODO: Use a less dated version of Ubuntu
FROM ubuntu:16.0
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -yq curl apt-transport-https && \
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list | tee /etc/apt/sources.list.d/mssql-server.list && \
apt-get update
RUN apt-get install -y mssql-server
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*
USER root
RUN (/opt/mssql/bin/mssql-conf set sqlagent.enabled true) && \
(/opt/mssql/bin/mssql-conf set hadr.hadrenabled 1)
# Run SQL Server process
CMD /opt/mssql/bin/sqlservr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment