Enhance local development experience using the Azure Cosmos DB Linux emulator and VS Code
Tags: vscode, docker, database, programming
Published: 2021-09-22 06:44:34

This blog post provides a quick overview and demo of how you can use the [Azure Cosmos DB Linux Emulator on Docker](https://docs.microsoft.com/azure/cosmos-db/linux-emulator?tabs=ssl-netstd21 "https://docs.microsoft.com/en-us/azure/cosmos-db/linux-emulator?tabs=ssl-netstd21") (in preview at the time of writing) along with [Visual Studio Code](https://code.visualstudio.com/ "https://code.visualstudio.com/") in order to enhance your local development experience.

Since the Azure Cosmos DB Linux Emulator is readily available as a Docker image (simply `docker pull mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator`), it's easy to incorporate it within your existing setup. For instance, it could be in a `docker-compose` file as a part of a larger stack (here is an [example of how to use it with Apache Kafka](https://devblogs.microsoft.com/cosmosdb/kafka-azure-cosmos-db-docker/)). However, complementing it with the [Visual Studio Code Remote - Containers](https://code.visualstudio.com/docs/remote/containers) extension, gives you the ability to leverage a Docker container as a full-fledged development environment. 

[![](https://code.visualstudio.com/assets/docs/remote/containers/architecture-containers.png)](https://code.visualstudio.com/assets/docs/remote/containers/architecture-containers.png)

Say you want to build an app with [Azure Cosmos DB Core (SQL) API](https://docs.microsoft.com/azure/cosmos-db/sql/sql-query-getting-started) and the [Java SDK](https://docs.microsoft.com/azure/cosmos-db/sql/sql-api-sdk-java-v4), and you have VS Code and Docker (optionally Docker Compose) available. Just create a JSON configuration file (called `devcontainer.json`) to define your stack. You can then spin up an environment on-demand with just a few clicks - this will constitute one or more Docker containers along with the entire operating system, programming language runtime (Java in this case), toolset, etc. which you originally specified in `devcontainer.json`. 

Some of the obvious benefits of using the emulator include: it's cost-effective (free!), convenient for scenarios when your app has other components (e.g. messaging systems) and great for iterative development/prototyping/demos since setting up and tearing down the environment is easy, consistent and error-free (in most cases!)  

### How to use the Azure Cosmos DB Linux emulator with VS Code

Use the instructions in this [GitHub repo](https://github.com/Azure-Samples/cosmosdb-java-devcontainers-demo) to get started quickly. It is based on the [original sample code repo for Azure Cosmos DB Java SDK for SQL API](https://github.com/Azure-Samples/azure-cosmos-java-sql-api-samples) with [added files](https://github.com/Azure-Samples/cosmosdb-java-devcontainers-demo/tree/main/.devcontainer) to enable "Visual Studio Code Remote - Containers" experience.

You can also follow along with the video that shows all of this in action:

{% youtube sMgmE3zuHNY %}

This example can be extended to any Java application. All you need to do is add the _.devcontainer_ folder to your current project and (maybe) tweak a few things depending on your requirement for e.g. the [Java version](https://github.com/Azure-Samples/cosmosdb-java-devcontainers-demo/blob/main/.devcontainer/Dockerfile#L5).

What this demonstrates is just the tip of the iceberg and you could leverage it in so many interesting ways. I look forward to hearing how you use it!

### More resources

*   Find [more ways to dev/test free](https://docs.microsoft.com/azure/cosmos-db/optimize-dev-test) with Azure Cosmos DB
*   Download the [Azure Cosmos DB local emulator](https://docs.microsoft.com/azure/cosmos-db/local-emulator?tabs=ssl-netstd21)
*   Review [technical documentation](https://docs.microsoft.com/azure/cosmos-db/) for Azure Cosmos DB