Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/nimanikoo/Dotnet-RateLimiter/llms.txt

Use this file to discover all available pages before exploring further.

The repository ships with a ready-to-use compose.yaml and a multi-stage Dockerfile that together spin up the entire Dotnet-RateLimiter infrastructure with a single command. The stack includes three services — the .NET 10 API, a Redis instance, and the RedisInsight monitoring UI — all wired together on a private bridge network. No manual configuration is required to get started locally.

Docker Compose Configuration

The full compose.yaml from the repository:
version: '3.8'

services:
  redis:
    image: redis:alpine
    container_name: rate-limit-redis
    ports:
      - "6379:6379"
    networks:
      - ratelimit-network

  api:
    image: ratelimiter-app
    build:
      context: .
      dockerfile: Dockerfile
    container_name: ratelimiter-api
    ports:
      - "8080:8080"
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - Redis__ConnectionString=redis:6379,abortConnect=false
    depends_on:
      - redis
    networks:
      - ratelimit-network

  redis-insight:
    image: redislabs/redisinsight:latest
    container_name: redis-insight
    ports:
      - "8001:8001"
    depends_on:
      - redis
    networks:
      - ratelimit-network

networks:
  ratelimit-network:
    driver: bridge
Notice that the api service uses Redis__ConnectionString=redis:6379,abortConnect=false — the double-underscore notation maps to the Redis:ConnectionString key in appsettings.json, overriding it with the Docker-internal hostname redis (the service name) instead of localhost. This is how the API container resolves Redis within the shared ratelimit-network.

Dockerfile

The application is built using a 4-stage Docker build for a minimal, optimized final image:
# Stage 1: Base Runtime
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

# Stage 2: Build
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src

COPY ["Dotnet-RateLimiter.csproj", "."]
RUN dotnet restore "./Dotnet-RateLimiter.csproj"

COPY . .
WORKDIR "/src/."
RUN dotnet build "./Dotnet-RateLimiter.csproj" -c $BUILD_CONFIGURATION -o /app/build

# Stage 3: Publish
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Dotnet-RateLimiter.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# Stage 4: Final
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Dotnet-RateLimiter.dll"]
StageBase ImagePurpose
basemcr.microsoft.com/dotnet/aspnet:10.0Lightweight runtime-only image; exposes ports 8080 and 8081
buildmcr.microsoft.com/dotnet/sdk:10.0Restores NuGet packages and compiles the project in Release mode
publishinherits buildPublishes the self-contained output to /app/publish with UseAppHost=false
finalinherits baseCopies only the published output into the slim runtime image
The SDK is never present in the final image — only the ASP.NET Core runtime and the compiled application artifacts are included, keeping the image footprint small.

Running the Stack

1

Clone the repository

git clone https://github.com/nimanikoo/Dotnet-RateLimiter.git
cd Dotnet-RateLimiter
2

Build and start all services

Run the full stack in detached mode. Docker Compose will build the API image, pull redis:alpine and redislabs/redisinsight:latest, and start all three containers:
docker-compose up --build -d
The depends_on directives ensure Redis starts before the API and RedisInsight containers attempt to connect. Watch the logs to confirm all services are healthy:
docker-compose logs -f
3

Access the running services

Once the stack is up, all three services are reachable on localhost:
ServiceURLDescription
APIhttp://localhost:8080ASP.NET Core 10 rate limiter API
Swagger UIhttp://localhost:8080/swaggerInteractive OpenAPI documentation (Development only)
Health Dashboardhttp://localhost:8080/health-uiReal-time health checks for Redis and the .NET runtime
Health Endpointhttp://localhost:8080/healthRaw JSON health check output
RedisInsight UIhttp://localhost:8001Visual Redis browser and key inspector
To connect RedisInsight to the running Redis instance, use:
  • Host: redis
  • Port: 6379
You can then watch rate_limit:* keys appear in real time as requests are processed, observe their counters, and monitor their TTL countdown.

Environment Variables

The api service accepts the following environment variables, set in compose.yaml or overridden at runtime:
VariableDefault (compose.yaml)Description
ASPNETCORE_ENVIRONMENTDevelopmentControls environment-specific behavior. Development enables Swagger UI and verbose logging.
Redis__ConnectionStringredis:6379,abortConnect=falseThe StackExchange.Redis connection string. The double-underscore maps to the Redis:ConnectionString configuration key. Inside the Docker network, use the service name redis as the hostname.

Docker Network

All three services (redis, api, redis-insight) are attached to the ratelimit-network bridge network defined at the bottom of compose.yaml:
networks:
  ratelimit-network:
    driver: bridge
This private bridge network provides DNS-based service discovery between containers (the API resolves redis by the service name), while isolating the stack from other Docker workloads on the host. Only the explicitly published ports (6379, 8080, 8001) are accessible from outside the network.
For production deployments: Replace the redis:alpine service with a managed Redis offering (such as Azure Cache for Redis, AWS ElastiCache, or Redis Cloud) and update the Redis__ConnectionString environment variable on the api service to point to the managed instance’s connection string. Remove the local redis and redis-insight service definitions from compose.yaml — RedisInsight is a development tool and should not be exposed in production. Ensure the managed Redis instance is accessible from your container host and that TLS is enabled on the connection string if required by your provider.

Build docs developers (and LLMs) love