DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Abhishek Gupta for Microsoft Azure

Posted on • Originally published at devblogs.microsoft.com

Enhance local development experience using the Azure Cosmos DB Linux emulator and VS Code

This blog post provides a quick overview and demo of how you can use theΒ Azure Cosmos DB Linux Emulator on DockerΒ (in preview at the time of writing) along withΒ Visual Studio CodeΒ 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). However, complementing it with the Visual Studio Code Remote - Containers extension, gives you the ability to leverage a Docker container as a full-fledged development environment.

Say you want to build an app withΒ Azure Cosmos DB Core (SQL) APIΒ and theΒ Java SDK, 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 to get started quickly. It is based on the original sample code repo for Azure Cosmos DB Java SDK for SQL APIΒ withΒ added files to enable "Visual Studio Code Remote - Containers" experience.

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

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.

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

Top comments (0)

Hacktoberfest is happening now!



It is a month-long celebration of open source. For a lot of devs, its their introduction to open source.


Check out the Hacktoberfest tag on DEV to keep up with the latest!