Skip to main content

Overview

AspNetRun Microservices uses environment variables extensively for configuration in containerized environments. These variables are defined in docker-compose.override.yml and override the default appsettings.json values.

Core ASP.NET Variables

All services use these standard ASP.NET Core environment variables:
VariableDescriptionDefault Value
ASPNETCORE_ENVIRONMENTSets the hosting environmentDevelopment
ASPNETCORE_HTTP_PORTSHTTP port for the service8080
ASPNETCORE_HTTPS_PORTSHTTPS port for the service8081

Database Environment Variables

PostgreSQL Databases

Used by Catalog and Basket services: CatalogDB Container:
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=CatalogDb
BasketDB Container:
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=BasketDb

SQL Server Database

Used by Ordering service: OrderDB Container:
ACCEPT_EULA=Y
SA_PASSWORD=SwN12345678

Service-Specific Variables

Catalog API

ASPNETCORE_ENVIRONMENT=Development
ASPNETCORE_HTTP_PORTS=8080
ASPNETCORE_HTTPS_PORTS=8081
ConnectionStrings__Database=Server=catalogdb;Port=5432;Database=CatalogDb;User Id=postgres;Password=postgres;Include Error Detail=true
Connection Details:
  • Database: PostgreSQL
  • Host: catalogdb (Docker service name)
  • Port: 5432
  • Database: CatalogDb

Basket API

ASPNETCORE_ENVIRONMENT=Development
ASPNETCORE_HTTP_PORTS=8080
ASPNETCORE_HTTPS_PORTS=8081
ConnectionStrings__Database=Server=basketdb;Port=5432;Database=BasketDb;User Id=postgres;Password=postgres;Include Error Detail=true
ConnectionStrings__Redis=distributedcache:6379
GrpcSettings__DiscountUrl=https://discount.grpc:8081
MessageBroker__Host=amqp://ecommerce-mq:5672
MessageBroker__UserName=guest
MessageBroker__Password=guest
Connection Details:
  • Database: PostgreSQL on basketdb:5432
  • Cache: Redis on distributedcache:6379
  • gRPC: Discount service at https://discount.grpc:8081
  • Message Broker: RabbitMQ at amqp://ecommerce-mq:5672

Discount gRPC

ASPNETCORE_ENVIRONMENT=Development
ASPNETCORE_HTTP_PORTS=8080
ASPNETCORE_HTTPS_PORTS=8081
ConnectionStrings__Database=Data Source=discountdb
Connection Details:
  • Database: SQLite with file discountdb
  • Protocol: HTTP/2 (gRPC)

Ordering API

ASPNETCORE_ENVIRONMENT=Development
ASPNETCORE_HTTP_PORTS=8080
ASPNETCORE_HTTPS_PORTS=8081
ConnectionStrings__Database=Server=orderdb;Database=OrderDb;User Id=sa;Password=SwN12345678;Encrypt=False;TrustServerCertificate=True
MessageBroker__Host=amqp://ecommerce-mq:5672
MessageBroker__UserName=guest
MessageBroker__Password=guest
FeatureManagement__OrderFullfilment=false
Connection Details:
  • Database: SQL Server on orderdb:1433
  • Message Broker: RabbitMQ at amqp://ecommerce-mq:5672
  • Feature Flags: OrderFullfilment disabled by default

YARP API Gateway

ASPNETCORE_ENVIRONMENT=Development
ASPNETCORE_HTTP_PORTS=8080
ASPNETCORE_HTTPS_PORTS=8081
Note: Routes and clusters are configured via appsettings.json (see ReverseProxy section).

Shopping Web

ASPNETCORE_ENVIRONMENT=Development
ASPNETCORE_HTTP_PORTS=8080
ASPNETCORE_HTTPS_PORTS=8081
ApiSettings__GatewayAddress=http://yarpapigateway:8080
Connection Details:
  • Gateway: YARP API Gateway at http://yarpapigateway:8080

Message Broker Variables

RabbitMQ is used for async communication between services: MessageBroker Container:
RABBITMQ_DEFAULT_USER=guest
RABBITMQ_DEFAULT_PASS=guest
Services Configuration:
MessageBroker__Host=amqp://ecommerce-mq:5672
MessageBroker__UserName=guest
MessageBroker__Password=guest
Used by: Basket API, Ordering API

Port Mappings

Services expose both HTTP and HTTPS ports mapped to the host:
ServiceHTTP PortHTTPS Port
Catalog API6000:80806060:8081
Basket API6001:80806061:8081
Discount gRPC6002:80806062:8081
Ordering API6003:80806063:8081
YARP Gateway6004:80806064:8081
Shopping Web6005:80806065:8081
Infrastructure services:
ServicePortDescription
CatalogDB5432:5432PostgreSQL
BasketDB5433:5432PostgreSQL
Redis6379:6379Distributed Cache
OrderDB1433:1433SQL Server
RabbitMQ5672:5672AMQP Protocol
RabbitMQ Management15672:15672Web UI

Volume Mappings

User secrets and HTTPS certificates are mounted from the host:
${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro
${APPDATA}/ASP.NET/Https:/home/app/.aspnet/https:ro
Data persistence volumes:
postgres_catalog:/var/lib/postgresql/data/
postgres_basket:/var/lib/postgresql/data/

Configuration Override Hierarchy

ASP.NET Core applies configuration in this order (later sources override earlier ones):
  1. appsettings.json (base configuration)
  2. appsettings.{Environment}.json (environment-specific)
  3. User Secrets (development only)
  4. Environment Variables (docker-compose.override.yml)
  5. Command-line arguments
In Docker environments, environment variables from docker-compose.override.yml take precedence over file-based settings.

Local Development vs Docker

Local Development (outside Docker):
  • Use appsettings.json with localhost hostnames
  • Database ports: 5432, 5433, 1433
  • Services run on ports: 6000-6005
Docker Environment:
  • Use Docker service names (catalogdb, basketdb, etc.)
  • Internal ports: 8080, 8081
  • Container-to-container communication on Docker network

Security Considerations

The default passwords shown here are for development only. Always use strong, unique passwords in production environments.
Sensitive values to change in production:
  • Database passwords (POSTGRES_PASSWORD, SA_PASSWORD)
  • RabbitMQ credentials (RABBITMQ_DEFAULT_USER, RABBITMQ_DEFAULT_PASS)
  • Connection strings (store in Azure Key Vault or similar)
  • Consider using Docker secrets or Kubernetes secrets for production deployments

Build docs developers (and LLMs) love