{"id":1671,"date":"2023-01-13T06:41:45","date_gmt":"2023-01-13T14:41:45","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/azure-sql\/?p=1671"},"modified":"2023-10-04T10:18:07","modified_gmt":"2023-10-04T17:18:07","slug":"development-with-sql-in-containers-on-macos","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azure-sql\/development-with-sql-in-containers-on-macos\/","title":{"rendered":"Development with SQL in containers on macOS"},"content":{"rendered":"<p>There are a bunch of <a href=\"https:\/\/learn.microsoft.com\/sql\/tools\/overview-sql-tools\">tools available<\/a> for developing with SQL on macOS, including the mssql extension for VS Code and the standalone yet-comfortably-familiar Azure Data Studio. As a developer, you might have heard about the <a href=\"https:\/\/aka.ms\/azuredbemulator\">Azure SQL Database emulator<\/a> and you&#8217;ve most certainly heard about <a href=\"https:\/\/learn.microsoft.com\/sql\/linux\/sql-server-linux-docker-container-deployment\">deploying SQL in containers<\/a>. Most recently, a new option for running SQL containers locally on your arm64 (M1\/M2) Mac became available and it makes running full SQL Server images easier than ever.<\/p>\n<p><!--more--><\/p>\n<p>In the v4.16 release of Docker Desktop, support for using Rosetta for emulation of x86\/amd64 images was introduced as a <a href=\"https:\/\/docs.docker.com\/release-lifecycle\/#beta\">beta feature,<\/a> enabling improved performance and stability for running container images built for x86\/amd64 on macOS 13 (Ventura).<\/p>\n<h2>Run SQL Server 2022 on macOS<\/h2>\n<p>Once you&#8217;ve enabled the new option under Settings in the &#8220;Features in development&#8221; pane, your will restart the local container runtime to apply the changes.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/dockerdesktop-beta.png\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-1672\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/dockerdesktop-beta-1024x581.png\" alt=\"Docker Desktop settings pane, last option is enabled for &quot;Use Rosetta for x86\/amd64 emulation on Apple Silicon&quot;\" width=\"640\" height=\"363\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/dockerdesktop-beta-1024x581.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/dockerdesktop-beta-300x170.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/dockerdesktop-beta-768x436.png 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/dockerdesktop-beta-1536x872.png 1536w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/dockerdesktop-beta.png 1835w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>From here on, we can follow the usual steps to pull a container image and run it:<\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">docker pull mcr.microsoft.com\/mssql\/server:2022-latest\r\ndocker run -e \"ACCEPT_EULA=Y\" -e \"MSSQL_SA_PASSWORD=&lt;YourStrong@Passw0rd&gt;\" \\\r\n   -p 1433:1433 --name sql2022 --hostname sql2022 \\\r\n   -d \\\r\n   mcr.microsoft.com\/mssql\/server:2022-latest<\/code><\/pre>\n<p>When you run the\u00a0<em>docker run<\/em> command for an amd64 image on a workstation with arm64, you will see a brief warning about the image architecture and the container id on the following line.<\/p>\n<pre>WARNING: The requested image's platform (linux\/amd64) does not match the detected host platform (linux\/arm64\/v8) and no specific platform was requested<\/pre>\n<p>If you&#8217;d prefer not to receive the warning message, you can include\u00a0<em>&#8211;platform linux\/amd64<\/em> in the\u00a0<em>docker run<\/em> command.\u00a0 The informational warning alerts you to the emulation that will occur to run the image in that environment.<\/p>\n<p>With Rosetta emulation for amd64 enabled, the SQL Server container will generally run with an indiscernible performance impact due to the emulation of amd64 binaries for arm64 and is suitable for development purposes.\u00a0 The SQL instance is now available to connect locally, whether from a tool such as Azure Data Studio or from an application being developed and run locally.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/running-container.png\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-1675\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/running-container-1024x231.png\" alt=\"Docker Desktop application interface showing list of running containers with SQL 2022 at top of list\" width=\"640\" height=\"144\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/running-container-1024x231.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/running-container-300x68.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/running-container-768x173.png 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/running-container.png 1165w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p><strong>Note:\u00a0<\/strong>If you have not installed Rosetta 2 on your machine, you may need to run this command:<\/p>\n<pre><code>softwareupdate --install-rosetta<\/code><\/pre>\n<h3>SQL container customization<\/h3>\n<p>We saw above an example command to pull the free Developer edition of SQL Server in a container and run it locally on port 1433.\u00a0 SQL containers can be customized with changes to the <em>docker run<\/em> command or with a Dockerfile for further configuration. Some popular options are:<\/p>\n<ul>\n<li>change the host port from 1433 to another port with <em>-p &lt;host port&gt;:1433<\/em><\/li>\n<li>store SQL data persistently with <em>-v &lt;host directory&gt;:\/var\/opt\/mssql<\/em><\/li>\n<\/ul>\n<h3>Comparison with arm64 Azure SQL Edge<\/h3>\n<p>The Azure SQL Database emulator offers 2 image options,\u00a0<em>Lite\u00a0<\/em>and <em>Full<\/em>, where the Full version is based on SQL Server container images while the Lite version is based on Azure SQL Edge container images.\u00a0 While the Lite (Azure SQL Edge) image offers a smaller image size, it also introduces feature limitations including a lack of spatial data types and hierarchyid data type.<\/p>\n<p>Azure SQL Edge also offers an arm64 image, which that runs without the host emulation layer that may show a performance impact under some workloads. For the perspective of a development environment, I&#8217;d like to offer a rudimentary comparison of the performance of Azure SQL Edge vs SQL Server 2022 running on an M1 Mac:<\/p>\n<p><figure id=\"attachment_1677\" aria-labelledby=\"figcaption_attachment_1677\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/sqlpackage-comparison.png\"><img decoding=\"async\" class=\"wp-image-1677 size-large\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/sqlpackage-comparison-1024x509.png\" alt=\"split screen of terminal with sqlpackage import commands on both sides\" width=\"640\" height=\"318\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/sqlpackage-comparison-1024x509.png 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/sqlpackage-comparison-300x149.png 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/sqlpackage-comparison-768x382.png 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/sqlpackage-comparison-1536x763.png 1536w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2023\/01\/sqlpackage-comparison.png 1795w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><figcaption id=\"figcaption_attachment_1677\" class=\"wp-caption-text\">SqlPackage import comparison<\/figcaption><\/figure><\/p>\n<p>On the left is a <a href=\"https:\/\/learn.microsoft.com\/sql\/tools\/sqlpackage\/sqlpackage\">SqlPackage<\/a> import of an AdventureWorks bacpac (388KB) to an arm64 Azure SQL Edge container and on the right is the same SqlPackage import operation to a SQL 2022 container running with Rosetta emulation. The Azure SQL Edge import took a fraction of a second longer than the SQL 2022 import, both of which completed in under 6 seconds.\u00a0 In this process, I&#8217;ve imported the database objects (tables, stored procs, indexes) as well as the data for a small sample database.<\/p>\n<h3>Get started with SQL containers on macOS<\/h3>\n<ul>\n<li>SQL container quickstart: <a href=\"https:\/\/learn.microsoft.com\/sql\/linux\/quickstart-install-connect-docker\">https:\/\/learn.microsoft.com\/sql\/linux\/quickstart-install-connect-docker<\/a><\/li>\n<li>Learn more about customizing SQL containers: <a href=\"https:\/\/learn.microsoft.com\/sql\/linux\/sql-server-linux-docker-container-configure\">https:\/\/learn.microsoft.com\/sql\/linux\/sql-server-linux-docker-container-configure<\/a><\/li>\n<li>Docker Desktop release notes for v4.16: <a href=\"https:\/\/docs.docker.com\/desktop\/release-notes\/#4160\">https:\/\/docs.docker.com\/desktop\/release-notes\/#4160<\/a><\/li>\n<li>Follow the Rosetta emulation support on the Docker Desktop roadmap: <a href=\"https:\/\/github.com\/docker\/roadmap\/issues\/384\">https:\/\/github.com\/docker\/roadmap\/issues\/384<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>There are a bunch of tools available for developing with SQL on macOS, including the mssql extension for VS Code and the standalone yet-comfortably-familiar Azure Data Studio. As a developer, you might have heard about the Azure SQL Database emulator and you&#8217;ve most certainly heard about deploying SQL in containers. Most recently, a new option [&hellip;]<\/p>\n","protected":false},"author":46830,"featured_media":81,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,484],"tags":[],"class_list":["post-1671","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure-sql","category-containers"],"acf":[],"blog_post_summary":"<p>There are a bunch of tools available for developing with SQL on macOS, including the mssql extension for VS Code and the standalone yet-comfortably-familiar Azure Data Studio. As a developer, you might have heard about the Azure SQL Database emulator and you&#8217;ve most certainly heard about deploying SQL in containers. Most recently, a new option [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/1671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/users\/46830"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/comments?post=1671"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/1671\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media\/81"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media?parent=1671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/categories?post=1671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/tags?post=1671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}