NoSQL Writer
This guide shows you how to work with Azure Cosmos DB locally using Docker and Python. This lab demonstrates how to connect a Python application to the Azure Cosmos DB Emulator.
Prerequisites
Section titled “Prerequisites”- Docker installed and running.
- Dev Containers extension installed (optional).
How to execute
Section titled “How to execute”-
Setup Environment:
Open VS Code in the project folder and execute this command in the Command Palette:
Terminal window > Dev Containers: Reopen in Container- Install dependencies:
Terminal window pip3 install uv && uv sync - Start Infrastructure: Launch the Cosmos DB Emulator:
Terminal window docker compose up -d cosmos
- Install dependencies:
-
Run the Example:
Terminal window python main.py
Validate results
Section titled “Validate results”Open the Cosmos DB Explorer in your browser:
http://localhost:1234/Install the Azure Cosmos DB extension from the VS Code marketplace and connect using the COSMOS_ENDPOINT and COSMOS_KEY defined in your .env.
Clean Up
Section titled “Clean Up”docker compose down -vTroubleshooting
Section titled “Troubleshooting”| Issue | Solution |
|---|---|
| Connection Refused | Ensure the emulator is running: docker ps |
PostgreSQL=FAIL in logs | Reset the emulator state: docker compose down -v |
| Evaluation period expired | Remove the old image (docker rmi mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator), pull latest, and restart. |