mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-22 17:22:59 -05:00
126 lines
6.0 KiB
Plaintext
126 lines
6.0 KiB
Plaintext
{
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"name": "python3",
|
|
"display_name": "Python 3"
|
|
},
|
|
"language_info": {
|
|
"name": "python",
|
|
"version": "3.6.6",
|
|
"mimetype": "text/x-python",
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"pygments_lexer": "ipython3",
|
|
"nbconvert_exporter": "python",
|
|
"file_extension": ".py"
|
|
}
|
|
},
|
|
"nbformat_minor": 2,
|
|
"nbformat": 4,
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": "\r\n## Run SQL Server 2019 CTP 3.1 container image with Docker\r\nThis notebook will use Docker to pull and run the SQL Server 2019 CTP 3.1 container image and connect to it in Azure Data Studio\r\n\r\n### Dependencies\r\n- Docker Engine. For more information, see [Install Docker](https://docs.docker.com/engine/installation/).",
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": "### Check dependencies",
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": "def run_command():\r\n print(\"Executing: \" + cmd)\r\n !{cmd}\r\n if _exit_code != 0:\r\n raise SystemExit(f'Shell command:\\n\\n\\t{cmd}\\n\\nreturned non-zero exit code: ' + str(_exit_code) + '.\\n')\r\n print(f'Successfully executed: {cmd}')\r\n\r\ncmd = 'docker version'\r\nrun_command()",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"execution_count": 1
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": "### List existing containers\r\nYou can view the ports that have been used by existing containers",
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": "cmd = f'docker ps -a'\r\nrun_command()",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"execution_count": 2
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": "### Required information",
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": "import getpass\r\npassword_name = 'SQL Server sa account password'\r\nsql_password = getpass.getpass(prompt = password_name)\r\npassword_confirm = getpass.getpass(prompt = f'Confirm {password_name}')\r\nif sql_password != password_confirm:\r\n raise SystemExit(f'{password_name} does not match the confirmation password')\r\nprint(f'{password_name}: ******')\r\nsql_port = input('SQL Server port, default value is 1433')\r\nif len(sql_port) == 0:\r\n sql_port = '1433'\r\nprint(f'Port: {sql_port}')",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"execution_count": 3
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": "### Pull the container image",
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": "cmd = f'docker pull mcr.microsoft.com/mssql/server:2019-latest'\r\nrun_command()",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"execution_count": 4
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": "### Start a new container",
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": "import time\r\ncontainer_name = 'sql2019-' + time.strftime(\"%Y%m%d%H%M%S\", time.localtime())\r\nprint('New container name: ' + container_name)\r\ncmd = f'docker run -e ACCEPT_EULA=Y -e \"SA_PASSWORD={sql_password}\" -p {sql_port}:1433 --name {container_name} -d mcr.microsoft.com/mssql/server:2019-latest'\r\nrun_command()",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"execution_count": 5
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": "### List all the containers",
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": "cmd = f'docker ps -a'\r\nrun_command()",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"execution_count": 6
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": "### Connect to SQL Server in Azure Data Studio\r\nIt might take a couple minutes for SQL Server to launch",
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": "from IPython.display import *\r\ndisplay(HTML(\"<a href=\\\"command:azdata.connect?{"serverName":"localhost,\"+sql_port+\"","providerName":"MSSQL", "authenticationType":"SqlLogin","userName":"sa","password":"\"+sql_password+\""}\\\">Click here to connect to SQL Server</a>\"))",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"execution_count": 7
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": "### Stop and remove the container",
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": "stop_container_command = f'docker stop {container_name}'\r\nremove_container_command = f'docker rm {container_name}'\r\ndisplay(HTML(\"Use this link to: <a href=\\\"command:workbench.action.terminal.focus\\\">open the terminal window in Azure Data Studio</a> and use the links below to paste the command to the terminal.\"))\r\ndisplay(HTML(\"Stop the container: <a href=\\\"command:workbench.action.terminal.sendSequence?%7B%22text%22%3A%22\"+stop_container_command.replace(\" \",\"%20\")+\"%22%7D\\\">\" + stop_container_command + \"</a>\"))\r\ndisplay(HTML(\"Remove the container: <a href=\\\"command:workbench.action.terminal.sendSequence?%7B%22text%22%3A%22\"+remove_container_command.replace(\" \",\"%20\")+\"%22%7D\\\">\" + remove_container_command + \"</a>\"))",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"execution_count": 8
|
|
}
|
|
]
|
|
}
|