August 16th, 2024

Simplify development with Dev Container templates for Azure SQL Database

Carlos Robles
Senior Product Manager

Image devcontainers azuresqlIn today’s fast-paced software development landscape, having a reliable and efficient local development setup is crucial. Dev Containers provide developers with a seamless way to build and test applications locally before deploying them to the cloud.

We are announcing the Public Preview of Dev Container templates for Azure SQL Database. This release provides pre-configured development environments tailored for Azure SQL Database, making it easier for developers to integrate and work with Azure SQL Database in their projects. In this blog post, we’ll explore these new development container templates, discuss their benefits, and guide you through setting up your development environment.

What are Dev Containers?

A development container essentially packages up your project’s development environment using the Development Container Specification (devcontainer.json). This specification enriches your container with metadata and content necessary to enable development from inside a container.

Workspace files are mounted from the local file system or copied or cloned into the container. Extensions are installed and run inside the container, where they have full access to the tools, platform, and file system. This means that you can seamlessly switch your entire development environment just by connecting to a different container.

Image architecture containers

Dev Container Templates are source files packaged together that encode configuration for a complete development environment, while Dev Container Features allow us to add runtimes, tools, and libraries inside a container. As a result, all this put together ensures a consistent and reproducible development environment from any tool that supports the Development Container Specification.

When you open your project in the dev container, your code will just work without downloading anything on your local machine. Furthermore, the best part is that when connected to a dev container, your developer experience is exactly the same as if you opened the project locally in VS Code.

Introducing Dev Container Templates for Azure SQL Database

We are excited to introduce new Dev Container templates specifically designed for Azure SQL Database. These templates support multiple programming languages, including .NET 8, .NET Aspire, Python, and Node.js, making it easier for developers to get started quickly and focus on building their applications.

Dev Containers streamline the development process by providing an out-of-the-box environment configured for Azure SQL Database. This eliminates the need for developers to spend time searching for and setting up VS Code extensions to interact with their database and preferred programming language. With these templates, you can dive straight into coding, boosting productivity and reducing setup friction.

Image dev containers azuresql

Included with the templates is a pre-built demo database called Library, which serves as a practical example to help developers get started quickly. While these Dev Containers use the Azure SQL Edge container image, which offers a surface area close to Azure SQL Database, using SQL Database Projects ensures that your database code remains compatible with Azure SQL Database. With this demo project, you can easily use the dacpac artifact created by SQL Database Projects and deploy it to Azure SQL Database using the Azure SQL Action for GitHub Actions. This process streamlines your workflow and ensures seamless integration with your production environment.

Whether working locally or in the cloud, dev containers ensure consistency across development environments, making it easier to collaborate and maintain high standards across your team. With the inclusion of essential tools like SQLCMD, SqlPackage, Azure Command-Line Interface (CLI) and Azure Developer CLI (AZD), these templates offer a comprehensive solution for enhancing your development workflow with Azure SQL Database.

Benefits of Using Dev Containers

Dev Containers ensure a consistent and seamless experience, promoting smooth collaboration across teams and workflows, and facilitating an easy transition to Azure environments. Key benefits include:

  • Preconfigured environments: These come with all necessary tools and dependencies.
  • Consistency: Maintain uniformity across different development setups.
  • Simplified setup: Reduce time spent on configuration.
  • Enhanced collaboration: Improve teamwork within development teams.
  • Seamless transition to Azure: Leverage the scalability and reliability of Azure SQL Database for production deployments.
  • Accelerated time-to-market: Streamline development workflows and integrate seamlessly with existing toolsets, giving businesses a competitive edge.
  • Cost-efficient development: Reduce dependencies on cloud resources during the development and testing phases.

By using dev containers, developers can avoid the hassle of setting up and configuring their local development environment manually.

Prerequisites

Before you begin, make sure you have the following tools installed on your local machine:

To set up your environment, follow these steps:

  1. First, ensure you have Git installed for version control.
  2. Then, install Docker, which is necessary for running containers.
  3. After that, download and install Visual Studio Code, as it will be your primary IDE for using Dev Containers.
  4. Lastly, add the Dev Containers extension to Visual Studio Code to enable seamless containerized development.

Setting up the Dev Container template for Azure SQL Database

Creating a Dev Container

Begin by either opening a local folder containing your application project or cloning an existing repository into Visual Studio Code. This initial step sets the stage for integrating your project with a development container, whether you’re starting from scratch or working on an existing application. In Visual Studio Code, open the command palette (press F1 or Ctrl+Shift+P on Windows and Cmd+Shift+P on macOS). Select the
Dev Containers: Add Dev Container Configuration Files command.

Image vscode command paletteSelect the Add configuration file to workspace option if you want to add the dev container configuration file to your current local repository. Alternatively, choose the Add configuration file to user data folder option. For this qiuckstart, select the Add configuration file to workspace option.Image vscode command palette configuration file 1Visual Studio Code prompts you to select a Dev Container template. The available templates are based on the tools and dependencies required for the specific development environment. Select Show All Definitions to view all available templates.Image vscode command palette configuration file 2Next, select the desired Dev Container template for Azure SQL Database by typing Azure SQL into the command palette. This action displays a list of available templates designed for Azure SQL Database development.Dev Container templates for Azure SQL Database

Building the Container

Upon selection, Visual Studio Code automatically generates the necessary configuration files tailored to the chosen template. These files include settings for the development environment, extensions to install, and Docker configuration details. They’re stored in a .devcontainer folder within your project directory, ensuring a consistent and reproducible development environment.Image vscode azure sql devcontainers create 1Following the configuration file generation, Visual Studio Code prompts you to transition your project into the newly created Dev Container environment. You can do it by selecting Reopen in Container. This step is crucial as it moves your development inside the container, applying the predefined environment settings for Azure SQL development.

If you haven’t already, you can also initiate this transition manually at any time using the Dev Containers extension. Use the Reopen in Container command from the command palette or select on the blue icon at the bottom left corner of Visual Studio Code and select Reopen in Container.Image vscode azure sql devcontainers create 2This action initiates the setup process, where Visual Studio Code generates the necessary configuration files and builds the development container based on the selected template. The process ensures that your development environment is precisely configured for Azure SQL Database development.

Visual Studio Code builds the container based on the selected configuration. The build process might take a few minutes the first time.

Image vscode azure sql devcontainers build

Image vscode azure sql devcontainers featuresExploring and verifying the Dev Container

After you build the dev container, start exploring and verifying the setup. Open a terminal within Visual Studio Code to check that all necessary tools are installed and working correctly.Image vscode azure sql devcontainers terminalAs an optional step, you can also run predefined tasks directly from the command palette, streamlining your development workflow and allowing you to focus on writing code.Image vscode azure sql devcontainers tasksImage vscode azure sql devcontainers task list

For more detailed information about specific templates, visit Azure SQL Database Dev Container templates.

Conclusion

Dev Containers for Azure SQL Database offer a powerful and efficient way to streamline your development process. By providing a consistent, portable environment, they help you focus on writing code and building features rather than configuring your setup. We encourage you to explore these templates and see how they can enhance your development workflow for Azure SQL Database.

Looking ahead, we will delve into more advanced topics like integrating Azure services with Dev Containers to further optimize your development process. Stay tuned for more insights and practical guides to help you get the most out of Azure SQL Database and Dev Containers.

Author

Carlos Robles
Senior Product Manager

With 12+ years navigating the tech landscape, I've evolved from a Software Developer to a Data specialist and later to a Solutions Architect, and now I work as a Product Manager at Microsoft. I've been honored with prestigious awards, including Microsoft MVP, and recognition in the Redgate 100 for DevOps excellence. Currently, I specialize in empowering developers to embrace Azure SQL. As an international speaker, author, and mentor, I thrive on catalyzing the adoption of Azure SQL among ...

More about author

0 comments

Discussion are closed.