Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Latest commit

 

History

History
159 lines (118 loc) · 5.65 KB

File metadata and controls

159 lines (118 loc) · 5.65 KB
title Run SQL Server Machine Learning Services in a container | Microsoft Docs
description This tutorial shows you how to use SQL Server Machine Learning Services in a Linux container running on Docker.
author uc-msft
ms.author umajay
ms.date 06/26/2019
ms.topic conceptual
ms.prod sql
ms.technology linux
ms.collection linux-container
moniker >= sql-server-linux-ver15 || =sqlallproducts-allversions

Run SQL Server Machine Learning Services in a container

[!INCLUDEappliesto-ss-xxxx-xxxx-xxx-md-linuxonly]

This tutorial demonstrates how to build a Docker container by using SQL Server Machine Learning Services, and how to run Machine Learning scripts from Transact-SQL. Coverage includes the following tasks:

[!div class="checklist"]

  • Clone the mssql-docker repository.
  • Build a SQL Server Linux container image with Machine Learning Services.
  • Run the SQL Server Linux container image with Machine Learning Services.
  • Run R or Python scripts by using Transact-SQL statements.
  • Stop and remove the SQL Server Linux container.

Prerequisites

Clone the mssql-docker repository

  1. Open a Bash terminal on Linux or Mac, or open a WSL terminal on Windows.

  2. Create a local directory to hold a local copy of the mssql-docker repository.

  3. Run the git clone command to clone the mssql-docker repository:

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

Build a SQL Server Linux container image with Machine Learning Services

  1. Change the directory to the mssql-mlservices directory:

    cd mssql-docker/linux/preview/examples/mssql-mlservices
  2. Run the build.sh script:

    ./build.sh

    [!NOTE] To build the Docker image, you must install packages that are several GBs in size. The script may take up to 20 minutes to finish running, depending on network bandwidth.

Run the SQL Server Linux container image with Machine Learning Services

  1. Set your environment variables before running the container. Set the PATH_TO_MSSQL environment variable to a host directory:

     export MSSQL_PID='Developer'
     export ACCEPT_EULA='Y'
     export ACCEPT_EULA_ML='Y'
     export PATH_TO_MSSQL='/home/mssql/'
  2. Run the run.sh script:

    ./run.sh

    This command creates a SQL Server container with Machine Learning Services, using the Developer edition (default). SQL Server port 1433 is exposed on the host as port 1401.

    [!NOTE] The process for running production SQL Server editions in containers is slightly different. For more information, see Configure SQL Server container images on Docker. If you use the same container names and ports, the rest of this walk-through still works with production containers.

  3. To view your Docker containers, run the docker ps command:

    sudo docker ps -a
  4. If the STATUS column shows a status of Up, SQL Server is running in the container and listening on the port specified in the PORTS column. If the STATUS column for your SQL Server container shows Exited, see the Troubleshooting section of the configuration guide.

    $ sudo docker ps -a

    Output:

    CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                    NAMES
    941e1bdf8e1d        mcr.microsoft.com/mssql/server/mssql-server-linux   "/bin/sh -c /opt/m..."   About an hour ago   Up About an hour     0.0.0.0:1401->1433/tcp   sql1
    

Change the SA password

[!INCLUDE Change docker password]

Execute R / Python scripts from Transact-SQL

  1. Connect to SQL Server in the container, and enable the external script configuration option by running the following T-SQL statement:

    EXEC sp_configure  'external scripts enabled', 1
    RECONFIGURE WITH OVERRIDE
    go
  2. Verify that Machine Learning Services is working by running the following simple R/Python sp_execute_external_script:

    execute sp_execute_external_script 
    @language = N'R',
    @script = N'
    print("Hello World!")
    print(R.version)
    print(Revo.version)
    OutputDataSet <- InputDataSet', 
    @input_data_1 = N'select 1'
    with result sets((i int));
    go
    execute sp_execute_external_script 
    @language = N'Python',
    @script = N'
    import sys
    print(sys.version)
    print("Hello World!")
    OutputDataSet = InputDataSet',
    @input_data_1 = N'select 1'
    with result sets((i int));
    go 

Next steps

In this tutorial, you learned to do the following:

[!div class="checklist"]

  • Clone the mssql-docker repository
  • Build SQL Server Linux container image with Machine Learning Services
  • Run SQL Server Linux container image with Machine Learning Services
  • Run R or Python scripts using Transact-SQL statements
  • Stop and remove the SQL Server Linux container

Next, review other Docker configuration and troubleshooting scenarios:

[!div class="nextstepaction"] Configuration guide for SQL Server on Docker