Zum Inhalt springen

Docker Compose to Aspire AppHost

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

This reference provides systematic mappings from Docker Compose YAML syntax to equivalent Aspire C# API calls. Use these tables as a quick reference when converting your existing Docker Compose files to Aspire application host configurations.

Docker ComposeAspireNotes
services:var builder = DistributedApplication.CreateBuilder(args)Root application builder used for adding and representing resources
service_name:builder.Add*("service_name")Service name becomes resource name

Learn more about Docker Compose services.

Docker ComposeAspireNotes
image: nginx:latestbuilder.AddContainer("name", "nginx", "latest")Direct image reference
build: .builder.AddDockerfile("name", ".")Build from Dockerfile
build: ./pathbuilder.AddDockerfile("name", "./path")Build from specific path
build.context: ./appbuilder.AddDockerfile("name", "./app")Build context
build.dockerfile: Custom.dockerfilebuilder.Add*("name").WithDockerfile("Custom.dockerfile")Custom Dockerfile name
Docker ComposeAspireNotes
build: ./MyApi (for .NET)builder.AddProject<Projects.MyApi>("myapi")Direct .NET project reference

Learn more about adding .NET projects.

Docker ComposeAspireNotes
ports: ["8080:80"].WithHttpEndpoint(port: 8080, targetPort: 80)HTTP endpoint mapping. Ports are optional; dynamic ports are used if omitted
ports: ["443:443"].WithHttpsEndpoint(port: 443, targetPort: 443)HTTPS endpoint mapping. Ports are optional; dynamic ports are used if omitted
expose: ["8080"].WithEndpoint(port: 8080)Internal port exposure. Ports are optional; dynamic ports are used if omitted
Docker ComposeAspire / Notes
environment: KEY=value.WithEnvironment("KEY", "value")
Static environment variable
environment: KEY=${HOST_VAR}.WithEnvironment(context => context.EnvironmentVariables["KEY"] = hostVar)
Environment variable with callback context
env_file: .env.ConfigureEnvFile(env => { ... })
Environment file generation (available in 13.1+)
Docker ComposeAspireNotes
volumes: ["data:/app/data"].WithVolume("data", "/app/data")Named volume
volumes: ["./host:/container"].WithBindMount("./host", "/container")Bind mount
volumes: ["./config:/app:ro"].WithBindMount("./config", "/app", isReadOnly: true)Read-only bind mount
Docker ComposeAspireNotes
depends_on: [db].WithReference(db)Service dependency with connection string injection
depends_on: db: condition: service_started.WaitFor(db)Wait for service start
depends_on: db: condition: service_healthy.WaitForCompletion(db)Wait for health check to pass
Docker ComposeAspireNotes
networks: [backend]AutomaticAspire handles networking automatically
Custom networksNot neededService discovery handles inter-service communication
Docker ComposeAspireNotes
deploy.resources.limits.memory: 512mNot supportedResource limits aren’t supported in Aspire
deploy.resources.limits.cpus: 0.5Not supportedResource limits aren’t supported in Aspire
Docker ComposeAspireNotes
healthcheck.test: ["CMD", "curl", "http://localhost/health"]Built-in for integrationsAspire integrations include health checks
healthcheck.interval: 30sConfigurable in integrationHealth check configuration varies by resource type
Docker ComposeAspireNotes
restart: unless-stoppedNot supportedRestart policies aren’t supported in Aspire
restart: alwaysNot supportedRestart policies aren’t supported in Aspire
restart: noDefaultNo restart policy

Learn more about Docker Compose restart.

Docker ComposeAspireNotes
logging.driver: json-fileBuilt-inAspire provides integrated logging
logging.options.max-size: 10mDashboard configurationManaged through Aspire dashboard

Learn more about Docker Compose logging and telemetry.

Docker ComposeAspireNotes
image: postgres:15builder.AddPostgres("name")PostgreSQL with automatic configuration
image: mysql:8builder.AddMySql("name")MySQL with automatic configuration
image: redis:7builder.AddRedis("name")Redis with automatic configuration
image: mongo:latestbuilder.AddMongoDB("name")MongoDB with automatic configuration
Fragen & AntwortenZusammenarbeitenCommunityDiskutierenAnsehen