Skip to main content
This page documents all environment variables and configuration options used across the Docker services.

Infrastructure Services

PostgreSQL Databases

Both catalogdb and basketdb use PostgreSQL with identical configuration patterns.

Catalog Database

catalogdb:
  environment:
    - POSTGRES_USER=postgres
    - POSTGRES_PASSWORD=postgres
    - POSTGRES_DB=CatalogDb
  ports:
    - "5432:5432"
  volumes:
    - postgres_catalog:/var/lib/postgresql/data/

Basket Database

basketdb:
  environment:
    - POSTGRES_USER=postgres
    - POSTGRES_PASSWORD=postgres
    - POSTGRES_DB=BasketDb
  ports:
    - "5433:5432"  # External port 5433 to avoid conflict
  volumes:
    - postgres_basket:/var/lib/postgresql/data/
Environment Variables:
VariableValueDescription
POSTGRES_USERpostgresDefault PostgreSQL superuser
POSTGRES_PASSWORDpostgresSuperuser password (change for production)
POSTGRES_DBCatalogDb/BasketDbInitial database name
Default credentials are used for development. Always use strong passwords and secure credential management in production.

SQL Server (Order Database)

orderdb:
  environment:
    - ACCEPT_EULA=Y
    - SA_PASSWORD=SwN12345678
  ports:
    - "1433:1433"
Environment Variables:
VariableValueDescription
ACCEPT_EULAYAccept SQL Server End-User License Agreement
SA_PASSWORDSwN12345678System administrator password (must meet complexity requirements)
SQL Server passwords must be at least 8 characters and contain uppercase, lowercase, numbers, and special characters.

Redis Cache

distributedcache:
  container_name: distributedcache
  restart: always
  ports:
    - "6379:6379"
Redis runs with default configuration. No authentication is configured for development.

RabbitMQ Message Broker

messagebroker:
  container_name: messagebroker
  hostname: ecommerce-mq
  environment:
    - RABBITMQ_DEFAULT_USER=guest
    - RABBITMQ_DEFAULT_PASS=guest
  ports:
    - "5672:5672"   # AMQP protocol
    - "15672:15672" # Management UI
Environment Variables:
VariableValueDescription
RABBITMQ_DEFAULT_USERguestDefault RabbitMQ user
RABBITMQ_DEFAULT_PASSguestDefault password
Access Management UI: http://localhost:15672 (guest/guest)

Application Services

Common ASP.NET Core Settings

All .NET services share these common environment variables:
environment:
  - ASPNETCORE_ENVIRONMENT=Development
  - ASPNETCORE_HTTP_PORTS=8080
  - ASPNETCORE_HTTPS_PORTS=8081
VariableValueDescription
ASPNETCORE_ENVIRONMENTDevelopmentEnables detailed errors, developer exception page
ASPNETCORE_HTTP_PORTS8080Internal HTTP port
ASPNETCORE_HTTPS_PORTS8081Internal HTTPS port

Catalog API

catalog.api:
  environment:
    - 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
  ports:
    - "6000:8080"
    - "6060:8081"
Connection String Format:
  • Server: catalogdb (container name)
  • Port: 5432 (PostgreSQL default)
  • Database: CatalogDb
  • User Id: postgres
  • Password: postgres
  • Include Error Detail: true (development only)

Basket API

basket.api:
  environment:
    - 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
  ports:
    - "6001:8080"
    - "6061:8081"
Additional Configuration:
VariableValueDescription
ConnectionStrings__Redisdistributedcache:6379Redis connection for caching
GrpcSettings__DiscountUrlhttps://discount.grpc:8081gRPC endpoint for discount service
MessageBroker__Hostamqp://ecommerce-mq:5672RabbitMQ AMQP connection
MessageBroker__UserNameguestRabbitMQ username
MessageBroker__PasswordguestRabbitMQ password

Discount gRPC Service

discount.grpc:
  environment:
    - ASPNETCORE_ENVIRONMENT=Development
    - ASPNETCORE_HTTP_PORTS=8080
    - ASPNETCORE_HTTPS_PORTS=8081
    - ConnectionStrings__Database=Data Source=discountdb
  ports:
    - "6002:8080"
    - "6062:8081"
Connection String:
  • Uses SQLite with file-based database discountdb
  • Database file stored in container filesystem

Ordering API

ordering.api:
  environment:
    - 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
  ports:
    - "6003:8080"
    - "6063:8081"
SQL Server Connection String:
  • Server: orderdb (container name)
  • Database: OrderDb
  • User Id: sa (system administrator)
  • Password: SwN12345678
  • Encrypt: False (development only)
  • TrustServerCertificate: True (development only)
Feature Flags:
VariableValueDescription
FeatureManagement__OrderFullfilmentfalseToggles order fulfillment feature

YARP API Gateway

yarpapigateway:
  environment:
    - ASPNETCORE_ENVIRONMENT=Development
    - ASPNETCORE_HTTP_PORTS=8080
    - ASPNETCORE_HTTPS_PORTS=8081
  ports:
    - "6004:8080"
    - "6064:8081"
Gateway routing configuration is stored in appsettings.json within the container.

Shopping Web Application

shopping.web:
  environment:
    - ASPNETCORE_ENVIRONMENT=Development
    - ASPNETCORE_HTTP_PORTS=8080
    - ASPNETCORE_HTTPS_PORTS=8081
    - ApiSettings__GatewayAddress=http://yarpapigateway:8080
  ports:
    - "6005:8080"
    - "6065:8081"
API Configuration:
VariableValueDescription
ApiSettings__GatewayAddresshttp://yarpapigateway:8080Internal gateway URL for API calls

Port Mappings

All port mappings follow the pattern HOST:CONTAINER:
ServiceHTTP (Host:Container)HTTPS (Host:Container)Purpose
catalog.api6000:80806060:8081Catalog service
basket.api6001:80806061:8081Basket service
discount.grpc6002:80806062:8081Discount service
ordering.api6003:80806063:8081Ordering service
yarpapigateway6004:80806064:8081API Gateway
shopping.web6005:80806065:8081Web UI
catalogdb5432:5432-PostgreSQL
basketdb5433:5432-PostgreSQL
orderdb1433:1433-SQL Server
distributedcache6379:6379-Redis
messagebroker5672:5672-RabbitMQ AMQP
messagebroker15672:15672-RabbitMQ Management

Volume Mounts

Database Persistence

volumes:
  - postgres_catalog:/var/lib/postgresql/data/
  - postgres_basket:/var/lib/postgresql/data/
Named volumes persist database data between container restarts.

Development Secrets and Certificates

All .NET services mount user secrets and HTTPS certificates:
volumes:
  - ${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro
  - ${APPDATA}/ASP.NET/Https:/home/app/.aspnet/https:ro
  • User secrets: Development-time secret storage
  • HTTPS certificates: Development SSL/TLS certificates
  • :ro flag: Read-only mount
The ${APPDATA} environment variable resolves to the Windows user’s AppData folder. For Linux/macOS, adjust these paths to ~/.microsoft/usersecrets and ~/.aspnet/https.

Configuration Hierarchy

ASP.NET Core configuration is loaded in this order (later sources override earlier ones):
  1. appsettings.json (in container)
  2. appsettings.{Environment}.json (e.g., appsettings.Development.json)
  3. User Secrets (development only)
  4. Environment variables (from docker-compose)
  5. Command-line arguments
Docker Compose environment variables use double underscore __ to represent configuration hierarchy:
ConnectionStrings__Database → ConnectionStrings:Database
MessageBroker__Host → MessageBroker:Host
FeatureManagement__OrderFullfilment → FeatureManagement:OrderFullfilment

Security Considerations

The current configuration is optimized for development and should not be used in production without modifications.

Production Checklist

  • Replace hardcoded credentials with Docker secrets or environment-specific secrets management
  • Use strong, unique passwords for all databases
  • Enable encryption for database connections (Encrypt=True)
  • Use trusted SSL certificates instead of TrustServerCertificate=True
  • Remove or secure database port exposure to host
  • Enable RabbitMQ authentication and SSL
  • Set ASPNETCORE_ENVIRONMENT=Production
  • Remove detailed error messages (Include Error Detail=true)
  • Use Azure Key Vault, AWS Secrets Manager, or HashiCorp Vault
  • Implement certificate rotation policies

Docker Secrets Example

secrets:
  db_password:
    file: ./secrets/db_password.txt

services:
  catalogdb:
    secrets:
      - db_password
    environment:
      - POSTGRES_PASSWORD_FILE=/run/secrets/db_password

Customizing Configuration

Override for Local Development

Create docker-compose.local.yml:
version: '3.4'

services:
  catalog.api:
    environment:
      - ConnectionStrings__Database=Server=localhost;Port=5432;Database=CatalogDb;User Id=myuser;Password=mypass
Run with:
docker-compose -f docker-compose.yml -f docker-compose.override.yml -f docker-compose.local.yml up

Environment-Specific Files

# Development
docker-compose -f docker-compose.yml -f docker-compose.override.yml up

# Staging
docker-compose -f docker-compose.yml -f docker-compose.staging.yml up

# Production
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up

Build docs developers (and LLMs) love