| 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 |
| manager | craigg |
| 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 |
[!INCLUDEappliesto-ss-xxxx-xxxx-xxx-md-linuxonly]
This tutorial demonstrates how to build a Docker container with SQL Server Machine Learning Services and run Machine Learning Scripts from Transact-SQL.
[!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.
- Git command-line interface.
- Docker Engine 1.8+ on any supported Linux distribution or Docker for Mac/Windows. For more information, see Install Docker.
- Minimum of 2 GB of disk space.
- Minimum of 2 GB of RAM.
- System requirements for SQL Server on Linux.
-
Open a bash terminal on Linux/Mac or WSL terminal on Windows.
-
Create a local directory to hold a copy of the mssql-docker repository locally.
-
Run the git clone command to clone the mssql-docker repository.
git clone https://github.com/microsoft/mssql-docker mssql-docker
-
Change directory to the mssql-mlservices directory.
cd mssql-docker/linux/preview/examples/mssql-mlservices -
Execute build.sh script.
./build.sh
[!NOTE] Building the docker image requires installing packages that are several GBs in size. The script may take up to 20 minutes to complete depending on network bandwidth.
-
Set environment variables before running the container. Set 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/'
-
Execute run.sh script.
./run.sh
This command creates a SQL Server container with Machine Learning Services with 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 Run production container images. If you use the same container names and ports, the rest of this walk-through still works with production containers.
-
To view your Docker containers, use the
docker pscommand.sudo docker ps -a
-
If the STATUS column shows a status of Up, then 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
[!INCLUDE Change docker password]
-
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
-
Verify 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
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