Microsoft SQL Server Docker

repository·master·Indexed 23 days ago

https://github.com/microsoft/mssql-docker

Dockerfiles and resources for running SQL Server in containerized environments on Linux and Windows. Includes guides for building customized images using setup.sql, configuring Machine Learning Services (R and Python), enabling PolyBase preview, and building images for various distributions including Ubuntu, openSUSE, CentOS, RHEL, and SLES.

Tokens
10.7K
Snippets
36
Records
68
Agent score
82%

What's inside microsoft-mssql-docker

  1. Choose a SQL Server Docker image flavor

    master

    SQL Server in Docker is available in two primary flavors depending on your host operating system and requirements:

    1. Linux-based containers: Uses SQL Server 2017 Developer Edition on an Ubuntu 16.04 base image. These are designed to run on Docker Engine across multiple platforms (Linux, macOS, Windows via Docker Desktop).
      • Includes Dockerfiles for building RHEL and CentOS based images.
    2. Windows-based containers: Uses SQL Server 2017 Express or Developer Edition. These must be run using Docker Engine for Windows Containers.

    Before using these for production, review the Microsoft SQL Server support policy.

  2. Quickstart: Deploy SQL Server using Helm

    master

    To deploy SQL Server using the provided Helm chart, follow these steps:

    1. Clone the repository.
    2. Navigate to the Rancher chart directory:
      cd linux/rancher
    3. Open values.example.yaml and update the sa password to your desired value.
    4. Execute the Helm installation command to create a namespace named sql-server and deploy the chart using the example values:
      helm install --create-namespace -n sql-server -f values.example.yaml .

    Note: By deploying this chart, you are agreeing to the SQL Server EULA.

    cd linux/rancher
    # Update sa password in values.example.yaml first
    helm install --create-namespace -n sql-server -f values.example.yaml .
  3. Run the PHP SQL Server Development Environment

    master

    The microsoft/msphpsql Docker image provides a pre-configured PHP 7.0 environment with SQL Server connectivity drivers (sqlsrv and pdo_sqlsrv), SQL Server command-line utilities (sqlcmd and bcp), and text editors (nano and vim).

    To start an interactive bash session in the container, use the following command:

    docker run -it microsoft/msphpsql
  4. Expose SQL Server externally and configure AG endpoints

    master

    The chart includes a services folder with manifests to extend the deployment:

    1. External Access: Use ex_service.yaml to create an external load balancer service for each pod, allowing SQL Server to be accessed from outside the cluster.
    2. AlwaysOn Availability Groups (AG): Use ag_endpoint.yaml to expose the AG endpoint ports within the cluster, enabling pods to communicate on the AG port.

    Apply these manifests using kubectl apply after the initial Helm installation.

    kubectl apply -f "D:\helm-charts\sql-statefull-deploy\services\ex_service.yaml"
    kubectl apply -f "D:\helm-charts\sql-statefull-deploy\services\ag_endpoint.yaml"
  5. Run the Node.js SQL Server development environment

    master

    The microsoft/tedious Docker image provides a pre-configured Node.js environment with the tedious driver, SQL Server command-line utilities (sqlcmd, bcp), and a code sample.

    To start an interactive bash session within the container, use the following command:

    docker run -it microsoft/tedious
  6. Run a customized MSSQL container

    master

    After building your custom image, start the container using docker run. You must provide the ACCEPT_EULA and MSSQL_SA_PASSWORD environment variables.

    Password Requirements: The MSSQL_SA_PASSWORD must be at least 8 characters long and contain uppercase, lowercase, and digits.

    docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=StrongPassw0rd' -p 1433:1433 --name sql1 -d mssql-custom
  7. Start a Microsoft SQL Server instance

    master

    To run a SQL Server instance using the official Ubuntu-based image, use docker run with the required environment variables. You must accept the EULA and provide a strong SA password.

    Requirements:

    • Docker Engine 1.8+
    • At least 3.25 GB of RAM
    • A strong SA password (at least 8 characters, including uppercase, lowercase, and base-10 digits/non-alphanumeric symbols).

    Note for Docker for Mac: Mapping volumes using -v is not supported. Use data volume containers for data persistence.

    docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d microsoft/mssql-server-linux
  8. Run the pyodbc Python development environment

    master

    To start an interactive bash session within the microsoft/pyodbc container, use the docker run command with the -it flags. This environment includes Ubuntu 16.04, Python 2.7, the pyodbc driver, SQL Server command-line utilities (sqlcmd, bcp), and text editors (nano, vim).

    docker run -it microsoft/pyodbc
  9. Configure database connection for the Node.js code sample

    master

    When running the container, you can pass environment variables to automatically configure the included connect.js code sample to point to your SQL Server instance:

    • DB_HOST: The IP address or hostname of the SQL Server instance.
    • DB_USERNAME: The database user.
    • DB_PASSWORD: The database user's password.

    Tip: If your SQL Server is also running in a Docker container, find its IP address using docker inspect <containerID>.

  10. Execute Python and SQL Server commands in the pyodbc container

    master

    Once inside the container, you can use the following commands to interact with your SQL Server instance:

    • Run the Python connection sample: Execute the pre-configured connect.py script.
    • Run the SQL Server command-line client: Use sqlcmd to execute T-SQL statements directly.

    Ensure you have provided the necessary environment variables ($DB_HOST, $DB_USERNAME, $DB_PASSWORD) for these commands to work correctly.