{"id":3395,"date":"2021-09-21T07:00:54","date_gmt":"2021-09-21T14:00:54","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cosmosdb\/?p=3395"},"modified":"2021-09-21T22:35:35","modified_gmt":"2021-09-22T05:35:35","slug":"linux-emulator-and-vs-code","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cosmosdb\/linux-emulator-and-vs-code\/","title":{"rendered":"Enhance local development experience using the Azure Cosmos DB Linux emulator and VS Code"},"content":{"rendered":"<p>This blog post provides a quick overview and demo of how you can use the\u00a0<a title=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cosmos-db\/linux-emulator?tabs=ssl-netstd21\" href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/linux-emulator?tabs=ssl-netstd21\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cosmos-db\/linux-emulator?tabs=ssl-netstd21\">Azure Cosmos DB Linux Emulator on Docker<\/a>\u00a0(in preview at the time of writing) along with\u00a0<a title=\"https:\/\/code.visualstudio.com\/\" href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/code.visualstudio.com\/\">Visual Studio Code<\/a>\u00a0in order to enhance your local development experience.<\/p>\n<p>Since the Azure Cosmos DB Linux Emulator is readily available as a Docker image (simply\u00a0<code>docker pull mcr.microsoft.com\/cosmosdb\/linux\/azure-cosmos-emulator<\/code>), it&#8217;s easy to incorporate it within your existing setup. For instance, it could be in a <code>docker-compose<\/code> file as a part of a larger stack (here is an\u00a0<a title=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/kafka-azure-cosmos-db-docker\/#\" href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/kafka-azure-cosmos-db-docker\/#\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/devblogs.microsoft.com\/cosmosdb\/kafka-azure-cosmos-db-docker\/#\">example of how to use it with Apache Kafka<\/a>). However, complementing it with the <a href=\"https:\/\/code.visualstudio.com\/docs\/remote\/containers\" target=\"_blank\" rel=\"noopener\">Visual Studio Code Remote &#8211; Containers<\/a> extension, gives you the ability to leverage a Docker container as a full-fledged development environment.<\/p>\n<p><a href=\"https:\/\/code.visualstudio.com\/assets\/docs\/remote\/containers\/architecture-containers.png\"><img decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/remote\/containers\/architecture-containers.png\" width=\"968\" height=\"402\" \/><\/a><\/p>\n<p>Say you want to build an app with\u00a0<a title=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cosmos-db\/sql\/sql-query-getting-started\" href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/sql\/sql-query-getting-started\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cosmos-db\/sql\/sql-query-getting-started\">Azure Cosmos DB Core (SQL) API<\/a>\u00a0and the\u00a0<a title=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cosmos-db\/sql\/sql-api-sdk-java-v4\" href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/sql\/sql-api-sdk-java-v4\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cosmos-db\/sql\/sql-api-sdk-java-v4\">Java SDK<\/a>, and you have VS Code and Docker (optionally Docker Compose) available. Just create a JSON configuration file (called <code>devcontainer.json<\/code>) to define your stack. You can then spin up an environment on-demand with just a few clicks &#8211; 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 <code>devcontainer.json<\/code>.<\/p>\n<p>Some of the obvious benefits of using the emulator include: it&#8217;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!)<\/p>\n<p>&nbsp;<\/p>\n<h3>How to use the Azure Cosmos DB Linux emulator with VS Code<\/h3>\n<p>Use the instructions in this <a title=\"https:\/\/github.com\/abhirockzz\/cosmosdb-java-devcontainers-demo\" href=\"https:\/\/github.com\/Azure-Samples\/cosmosdb-java-devcontainers-demo\" data-href=\"https:\/\/github.com\/abhirockzz\/cosmosdb-java-devcontainers-demo\">GitHub repo<\/a> to get started quickly. It is based on the <a title=\"https:\/\/github.com\/Azure-Samples\/azure-cosmos-java-sql-api-samples\" href=\"https:\/\/github.com\/Azure-Samples\/azure-cosmos-java-sql-api-samples\" data-href=\"https:\/\/github.com\/Azure-Samples\/azure-cosmos-java-sql-api-samples\">original sample code repo for Azure Cosmos DB Java SDK for SQL API<\/a>\u00a0with\u00a0<a title=\"https:\/\/github.com\/abhirockzz\/cosmosdb-java-devcontainers-demo\/tree\/master\/.devcontainer\" href=\"https:\/\/github.com\/Azure-Samples\/cosmosdb-java-devcontainers-demo\/tree\/main\/.devcontainer\" data-href=\"https:\/\/github.com\/abhirockzz\/cosmosdb-java-devcontainers-demo\/tree\/master\/.devcontainer\">added files<\/a> to enable &#8220;Visual Studio Code Remote &#8211; Containers&#8221; experience.<\/p>\n<p>You can also follow along with the video that shows all of this in action:<\/p>\n<p><iframe title=\"YouTube video player\" src=\"https:\/\/www.youtube.com\/embed\/sMgmE3zuHNY\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p class=\"code-line\" data-line=\"23\">This example can be extended to any Java application. All you need to do is add the <em>.devcontainer<\/em> folder to your current project and (maybe) tweak a few things depending on your requirement for e.g. the <a href=\"https:\/\/github.com\/Azure-Samples\/cosmosdb-java-devcontainers-demo\/blob\/main\/.devcontainer\/Dockerfile#L5\">Java version<\/a>.<\/p>\n<p class=\"code-line\" data-line=\"23\">What this demonstrates is just the tip of the iceberg and you could leverage it in so many interesting ways.\u00a0I look forward to hearing how you use it!<\/p>\n<h3 data-line=\"23\">More resources<\/h3>\n<ul>\n<li>Find <a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/optimize-dev-test\" target=\"_blank\" rel=\"noopener\">more ways to dev\/test free<\/a> with Azure Cosmos DB<\/li>\n<li data-line=\"23\">Download the<a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/local-emulator?tabs=ssl-netstd21\" target=\"_blank\" rel=\"noopener\"> Azure Cosmos DB local emulator<\/a><\/li>\n<li data-line=\"23\">Review <a href=\"https:\/\/docs.microsoft.com\/azure\/cosmos-db\/\" target=\"_blank\" rel=\"noopener\">technical documentation<\/a> for Azure Cosmos DB<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Develop your next app database locally using the Azure Cosmos DB Linux emulator on Docker (preview) with Visual Studio Code. This post includes a sample with GitHub repository and a step-by-step video. <\/p>\n","protected":false},"author":38710,"featured_media":61,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[14,643,19],"tags":[1783,1784,537,498],"class_list":["post-3395","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-sql-api","category-java-sdk","category-tips-and-tricks","tag-docker","tag-emulator","tag-java","tag-visual-studio-code"],"acf":[],"blog_post_summary":"<p>Develop your next app database locally using the Azure Cosmos DB Linux emulator on Docker (preview) with Visual Studio Code. This post includes a sample with GitHub repository and a step-by-step video. <\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/3395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/users\/38710"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/comments?post=3395"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/posts\/3395\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media\/61"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/media?parent=3395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/categories?post=3395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cosmosdb\/wp-json\/wp\/v2\/tags?post=3395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}