Last active
August 25, 2024 01:30
-
-
Save tap52384/449eaeecfde0180caeca574af5ea936f to your computer and use it in GitHub Desktop.
Revisions
-
tap52384 revised this gist
Aug 25, 2024 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -59,6 +59,7 @@ What we need are the shell commands for pulling (downloading) the Docker image l computer so that we can use it with Docker. Enter this command in your terminal to download the image to your computer. ```bash # Downloads Microsoft's official Docker image for Azure SQL Edge (SQL Server for IoT) to your computer docker pull mcr.microsoft.com/azure-sql-edge # To see what images are on your computer: @@ -85,6 +86,8 @@ These password requirements are confirmed [in the documentation](https://learn.m > generate and store a password just in case, even if this is for local development. ```bash # Creates a container and starts it while opening access to port 1433 # both inside and outside the container for access to SQL Server from Azure Data Studio docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=yourStrong(!)Password1' -e 'MSSQL_PID=Developer' -p 1433:1433 --name azuresqledge -d mcr.microsoft.com/azure-sql-edge # Run this command to confirm that the container named "azuresqledge" is running -
tap52384 revised this gist
Aug 25, 2024 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,10 +56,13 @@ Docker containers: - [Microsoft SQL Server](https://hub.docker.com/r/microsoft/mssql-server) What we need are the shell commands for pulling (downloading) the Docker image locally to our computer so that we can use it with Docker. Enter this command in your terminal to download the image to your computer. ```bash docker pull mcr.microsoft.com/azure-sql-edge # To see what images are on your computer: docker image ls ``` ## 5. [Run the SQL Image in a Container](https://youtu.be/9c7Ti2OcLZg?t=420) -
tap52384 revised this gist
Aug 25, 2024 . 1 changed file with 22 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -142,3 +142,25 @@ created, where `dbo` is the `schema` (which works like a group) that the `Person Right-click the `dbo.Persons` table and choose **Select Top 1000** to run a `SELECT` query on the `dbo.Persons` table to see the three rows that we added in the code above using the `INSERT INTO` statement. ## 7. Starting and Stopping the SQL Server Docker Container If you attempt to connect to `localhost,1433` from Azure Data Studio and you cannot connect, the first thing to check is whether Docker itself is running and whether the Docker container that we created, `azuresqledge`, is running. From the Docker Desktop application, on the left-hand side, go to Containers. If you do not see the `azuresqledge` container, turn off the option to **Only show running containers**. Under the **Actions** column, you can choose to stop and start the container. From the terminal, you can use the following commands: ```bash # Show all containers regardless if they are running or not docker ps -a # Stop the container docker container stop azuresqledge # Start the container docker container start azuresqledge # Create the container and start it in case it does not exist # This command will fail if a container with the same name already exists # This is the same command as above docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=yourStrong(!)Password1' -e 'MSSQL_PID=Developer' -p 1433:1433 --name azuresqledge -d mcr.microsoft.com/azure-sql-edge ``` -
tap52384 created this gist
Aug 24, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,144 @@ # Get SQL Server 2022 Running on macOS via Docker These directions are based on [this YouTube video](https://youtu.be/9c7Ti2OcLZg). The comments helped with making sure I was able to connect to the Azure SQL Edge (SQL Server) instance running via Docker the first time. ## 0. Install Homebrew Homebrew is an open source package manager for macOS and Linux. ALthough we will not need it for these instructions, if you do not have the `brew` command already, this will install it. Open Terminal on your Mac and execute the following command: ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` This will require you to enter your password for logging into your account on your computer. ## 1. [Install Docker](https://youtu.be/9c7Ti2OcLZg?t=44) You can download Docker Desktop [from this page](https://docs.docker.com/desktop/install/mac-install/). Docker is software that runs containers which are like small virtual machines designed to handle smaller portions of an application. In this example, we just need to run a database server. ## 2. [Install Azure Data Studio](https://youtu.be/9c7Ti2OcLZg?t=154) You can download and [install Azure Data Studio from this page](https://learn.microsoft.com/en-us/azure-data-studio/download-azure-data-studio?tabs=macOS-install%2Cwin-user-install%2Credhat-install%2Cwindows-uninstall%2Credhat-uninstall#download-azure-data-studio). Azure Data Studio is the application that will allow us to interact with the database that we will run from the Docker container. This will enable us to run SQL statements and learn SQL. ## 3. [Create a Docker ID](https://youtu.be/9c7Ti2OcLZg?t=259) A Docker ID is an account to use with the Docker Desktop application. To create an account, go to [docker.com](https://www.docker.com/get-started/), click **Sign In**. At the bottom of the page, click the **Don't have an account? Sign Up** link and create an account. Once your account is created, it is recommended to enable two-factor authentication in the **Account Settings** once you have logged in. Once you have created the Docker account, open the Docker Desktop application your computer. Click the **Sign In** button in the upper right-hand corner of the application. ## 4. [Download the Official Microsoft SQL Container Image](https://youtu.be/9c7Ti2OcLZg?t=344) What exactly is [Azure SQL Edge](https://learn.microsoft.com/en-us/azure/azure-sql-edge/overview)? It is an optimized database made for IoT (Internet of Things) that is built on the same engine as SQL Server and Azure SQL. Azure SQL Edge also provides the same Transact-SQL (T-SQL) programming functionality. Docker containers: - [Azure SQL Edge](https://hub.docker.com/r/microsoft/azure-sql-edge) - [Microsoft SQL Server](https://hub.docker.com/r/microsoft/mssql-server) What we need are the shell commands for pulling (downloading) the Docker image locally to our computer so that we can use it with Docker. ```bash docker pull mcr.microsoft.com/azure-sql-edge ``` ## 5. [Run the SQL Image in a Container](https://youtu.be/9c7Ti2OcLZg?t=420) In Docker terms, a container is a running instance of an image. Therefore, the `docker run` command creates a container from the Azure SQL Edge docker image that was downloaded in the previous step. For the `MSSQL_SA_PASSWORD` parameter in the command below, change the text `yourStrong(!)Password` to a password with at least 8 characters containing at least one of each: - uppercase letter - lowercase letter - digit - symbol These password requirements are confirmed [in the documentation](https://learn.microsoft.com/en-us/sql/relational-databases/security/password-policy?view=sql-server-ver16#password-complexity). > The **SA** in `MSSQL_SA_PASSWORD` stands for system administrator, which means the `MSSQL_SA_PASSWORD` > parameter is setting the system administrator account on SQL Server (username: SA). You should > generate and store a password just in case, even if this is for local development. ```bash docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=yourStrong(!)Password1' -e 'MSSQL_PID=Developer' -p 1433:1433 --name azuresqledge -d mcr.microsoft.com/azure-sql-edge # Run this command to confirm that the container named "azuresqledge" is running docker ps -a ``` > According to the documentation for the Docker image, the `MSSQL_PID` environment flag defaults to > "Developer". `MSSQL_PID` determines the edition of Azure SQL Edge that will run in the container. > More documentation on how to configure Azure SQL Edge can be found [here](https://learn.microsoft.com/en-us/azure/azure-sql-edge/configure#configure-by-using-environment-variables). In the video, the presenter uses the `MSSQL_USER` parameter and sets it to `SA`. However, I could not find documentation for this parameter and therefore, it should not be used. ## 6. [Connect Azure Data Studio to the Docker Image](https://youtu.be/9c7Ti2OcLZg?t=502) Open Azure Data Studio and create a connection. In the **Connection Details** pane, enter the following: - **Connection type** - `Microsoft SQL Server` - **Server** - `localhost,1433` - **Authentication type** - `SQL Login` - **User name** - `SA` - **Password** - `yourStrong(!)Password1` - **Trust server certificate** - `True` > **Trust server certificate** is required because you will be prompted by Azure Data Studio that > the certificate inside the container is invalid, which is to be expected. Here is the code that the video used to create a table and add some data: ```sql CREATE TABLE Persons ( [PersonID] int, [LastName] varchar(255), [FirstName] varchar(255), [Address] varchar(255), [City] varchar(255) ); BEGIN TRANSACTION INSERT INTO Persons (PersonID, LastName, FirstName, [Address], City) VALUES (1, 'Smith', 'John', '31 Central Park', 'New York'), (2, 'Damon', 'Matt', '5 Gold Lane', 'San Francisco'), (3, 'Prescott', 'Dak', 'The Star', 'Dallas') ; COMMIT TRANSACTION; ``` To run this code, on the left-hand side, find your server, **localhost,1433** and expand **Databases** --> **System Databases**. Right-click the `master` database and choose **New Query**. You can also start a new query document by going to **File --> New Query** from the Finder bar or by pressing `CMD + N`. Once you copy and paste the code above into the query document and run it, if you expand the **Tables** folder under the **master** database, you should see the `dbo.Persons` table has been created, where `dbo` is the `schema` (which works like a group) that the `Persons` table belongs to. Right-click the `dbo.Persons` table and choose **Select Top 1000** to run a `SELECT` query on the `dbo.Persons` table to see the three rows that we added in the code above using the `INSERT INTO` statement.