Deploy Azure SQL Edge with Docker
In this quickstart, you use Docker to pull and run the Azure SQL Edge container image. Then connect with sqlcmd to create your first database and run queries.
This image consists of SQL Edge based on Ubuntu 18.04. It can be used with the Docker Engine 1.8+ on Linux.
Azure SQL Edge containers aren't supported on the following platforms for production workloads:
- Azure IoT Edge for Linux on Windows (EFLOW)
- Docker Engine 1.8+ on any supported Linux distribution. For more information, see Install Docker. Since the SQL Edge images are based on Ubuntu 18.04, we recommended that you use an Ubuntu 18.04 Docker host.
- Docker overlay2 storage driver. This is the default for most users. If you find that you aren't using this storage provider and need to change, see the instructions and warnings in the Docker documentation for configuring overlay2.
- Minimum of 10 GB of disk space.
- Minimum of 1 GB of RAM.
- Hardware requirements for Azure SQL Edge.
For the bash commands in this article
sudo is used. If you don't want to use
sudo to run Docker, you can configure a Docker group and add users to that group. For more information, see Post-installation steps for Linux.
Pull and run the container image
Pull the Azure SQL Edge container image from Microsoft Container Registry.
sudo docker pull mcr.microsoft.com/azure-sql-edge:latest
The previous command pulls the latest SQL Edge container image. To see all available images, see the azure-sql-edge Docker hub page.
To run the container image with Docker, use the following command from a bash shell:
Start an Azure SQL Edge instance running as the Developer edition:
sudo docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 --name azuresqledge -d mcr.microsoft.com/azure-sql-edge
Start an Azure SQL Edge instance running as the Premium edition:
sudo docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=yourStrong(!)Password' -e 'MSSQL_PID=Premium' -p 1433:1433 --name azuresqledge -d mcr.microsoft.com/azure-sql-edge
The password should follow the Microsoft SQL Database Engine default password policy, otherwise the container can't set up the SQL Database Engine and will stop working. By default, the password must be at least 8 characters long and contain characters from three of the following four sets: uppercase letters, lowercase letters, base-10 digits, and symbols. You can examine the error log by executing the docker logs command.
The following table provides a description of the parameters in the previous
Parameter Description -e "ACCEPT_EULA=Y" Set the ACCEPT_EULA variable to any value to confirm your acceptance of the End-User Licensing Agreement. Required setting for the SQL Edge image. -e "MSSQL_SA_PASSWORD=yourStrong(!)Password" Specify your own strong password that is at least 8 characters and meets the Azure SQL Edge password requirements. Required setting for the SQL Edge image. -p 1433:1433 Map a TCP port on the host environment (first value) with a TCP port in the container (second value). In this example, SQL Edge is listening on TCP 1433 in the container and this is exposed to the port, 1433, on the host. --name azuresqledge Specify a custom name for the container rather than a randomly generated one. If you run more than one container, you can't reuse this same name. -d Run the container in the background (daemon)
For a complete list of all Azure SQL Edge environment variable, see Configure Azure SQL Edge with Environment Variables.You can also use a mssql.conf file to configure SQL Edge containers.
To view your Docker containers, use the
sudo docker ps -a
If the STATUS column shows a status of Up, then SQL Edge is running in the container and listening on the port specified in the PORTS column. If the STATUS column for your SQL Edge container shows Exited, see the Troubleshooting section of Azure SQL Edge documentation.
-h(host name) parameter is also useful, but it isn't used in this tutorial for simplicity. This changes the internal name of the container to a custom value. This is the name you'll see returned in the following Transact-SQL query:
SELECT @@SERVERNAME, SERVERPROPERTY('ComputerNamePhysicalNetBIOS'), SERVERPROPERTY('MachineName'), SERVERPROPERTY('ServerName')
--nameto the same value is a good way to easily identify the target container.
As a final step, change your SA password because the
MSSQL_SA_PASSWORDis visible in
ps -eaxoutput and stored in the environment variable of the same name. See the following steps.
Change the SA password
The SA account is a system administrator on the Azure SQL Edge instance that gets created during setup. After creating your SQL Edge container, the
MSSQL_SA_PASSWORD environment variable you specified is discoverable by running
echo $MSSQL_SA_PASSWORD in the container. For security purposes, change your SA password.
Choose a strong password to use for the SA user.
docker execto run sqlcmd to change the password using Transact-SQL. In the following example, replace the old password,
<YourStrong!Passw0rd>, and the new password,
<YourNewStrong!Passw0rd>, with your own password values.
sudo docker exec -it azuresqledge /opt/mssql-tools/bin/sqlcmd \ -S localhost -U SA -P "<YourStrong@Passw0rd>" \ -Q 'ALTER LOGIN SA WITH PASSWORD="<YourNewStrong@Passw0rd>"'
Connect to Azure SQL Edge
The following steps use the Azure SQL Edge command-line tool, sqlcmd, inside the container to connect to SQL Edge.
sqlcmd is not available inside the ARM64 version of SQL Edge containers.
docker exec -itcommand to start an interactive bash shell inside your running container. In the following example,
azuresqledgeis the name specified by the
--nameparameter when you created the container.
sudo docker exec -it azuresqledge "bash"
Once inside the container, connect locally with sqlcmd. Sqlcmd isn't in the path by default, so you have to specify the full path.
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "<YourNewStrong@Passw0rd>"
You can omit the password on the command-line to be prompted to enter it.
If successful, you should get to a sqlcmd command prompt:
Create and query data
The following sections walk you through using sqlcmd and Transact-SQL to create a new database, add data, and run a query.
Create a new database
The following steps create a new database named
From the sqlcmd command prompt, paste the following Transact-SQL command to create a test database:
CREATE DATABASE TestDB Go
On the next line, write a query to return the name of all of the databases on your server:
SELECT Name from sys.Databases Go
Next create a new table,
Inventory, and insert two new rows.
From the sqlcmd command prompt, switch context to the new
Create new table named
CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT);
Insert data into the new table:
INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
GOto execute the previous commands:
Now, run a query to return data from the
From the sqlcmd command prompt, enter a query that returns rows from the
Inventorytable where the quantity is greater than 152:
SELECT * FROM Inventory WHERE quantity > 152;
Execute the command:
Exit the sqlcmd command prompt
To end your sqlcmd session, type
To exit the interactive command-prompt in your container, type
exit. Your container continues to run after you exit the interactive bash shell.
Connect from outside the container
You can also connect to the SQL Edge instance on your Docker machine from any external Linux, Windows, or macOS tool that supports SQL connections. For more information on connecting to a SQL Edge container from outside, refer Connect and Query Azure SQL Edge.
Remove your container
If you want to remove the SQL Edge container used in this tutorial, run the following commands:
sudo docker stop azuresqledge sudo docker rm azuresqledge
Stopping and removing a container permanently deletes any SQL Edge data in the container. If you need to preserve your data, create and copy a backup file out of the container or use a container data persistence technique.