This repo demonstrates a working docker-compose.yml that includes:
The purpose of this is to provide an example of how to configure docker-compose for a local development environment that only requires the developer to run one command to have all required services running on their local machine in docker containers.
The aim of this is to demonstrate a working example.
- .Net 7 SDK
- Docker for Windows (or regular docker on Linux)
cosmosdb
: Azure Cosmos DB Emulator for Linuxazurite
: Azurite (Azure storage emulator)rabbitmq
: RabbitMQ AMQP services
- You have the requirements listed above installed
- You have no other services running on any of the following ports:
- 5672
- 8081
- 8900-8901
- 8979
- 10000-10002
- 10250-10256
- 10350
- 15672
- You do not already have Azurite running elsewhere.
- You do not have the (now deprecated) Azure Storage Emulator running
Note: You may have an instance of Azurite or the older storage emulator running without realising it if you have opened another project that has a connection string
UseDevelopmentStorage=true
. Visual Studio will start its own instance automatically when it detects it is needed. Note that the Visual Studio Azurite/Emulator instance does not shut down when you close Visual Studio - you must restart your computer.
- Clone the repository
- Open your command line client that can use docker CLI commands and
cd
to the repository root - Run the command
docker compose up -d
This will start all of the services, all running on their default ports.
If you only wish to start one of the services you can do so by specifying the service name on the end of the command:
# Only start Cosmos DB
docker compose up -d cosmosdb
# Only start azurite
docker compose up -d azurite
# Only start RabbityMQ
docker compose up -d rabbitmq
When you've finished using the services for the day it's a good idea to spin down the containers to free up system resources. There are two ways to do this.
- Open your command line client that can use docker CLI commands and
cd
to the repository root - Run the command
docker compose down
Note: This will not remove any data from docker volumes
- Open your command line client that can use docker CLI commands and
cd
to the repository root - Run the command
docker compose stop
How you restart the services the next time depends on how you closed them down.
Use docker compose up -d
to spin them up again as this will recreate the containers.
Use docker compose start
instead.
- Cosmos Explorer: https://localhost:8081/_explorer/index.html
- RabbitMQ Manager: http://localhost:15672/ (u:
guest
| p:guest
) - Azurite: Use Azure Storage Explorer to connect to the local storage emulator.
- Ensure that your docker containers are running as described above.
- Ensure that you have trusted the dotnet developer certificates by running the command
dotnet dev-certs https --trust
- Open the api solution in visual Studio or Jetbrains Rider.
- Run the "https" runtime configuration (it should be the only one available)
This will open Swagger in your default browser. There are two POST endpoints available:
This endpoint will create a TestEntity
in your cosmosdb instance. You can verify this with the Cosmos Explorer.
This endpoint will do two things:
- Publish a notification to RabbitMQ. You can verify this by checking to see if an exchange exists named after the fully qualified type used for the message (in this case
Host.Models.TestMessage
). If you view the exchange immediately after running the endpoint you will see the spike in the graph showing the message being sent. - Send a message to a queue in RabbitMQ. You can verify this by locating a queue with the name "test" in the queues section. Within this queue you can use the management console to get the messages and see their data.