Docker Compose to Aspire AppHost
이 콘텐츠는 아직 번역되지 않았습니다.
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.
Service definitions
Section titled “Service definitions”| Docker Compose | Aspire | Notes |
|---|---|---|
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.
Images and builds
Section titled “Images and builds”| Docker Compose | Aspire | Notes |
|---|---|---|
image: nginx:latest | builder.AddContainer("name", "nginx", "latest") | Direct image reference |
build: . | builder.AddDockerfile("name", ".") | Build from Dockerfile |
build: ./path | builder.AddDockerfile("name", "./path") | Build from specific path |
build.context: ./app | builder.AddDockerfile("name", "./app") | Build context |
build.dockerfile: Custom.dockerfile | builder.Add*("name").WithDockerfile("Custom.dockerfile") | Custom Dockerfile name |
Learn more about Docker Compose build reference and WithDockerfile.
.NET projects
Section titled “.NET projects”| Docker Compose | Aspire | Notes |
|---|---|---|
build: ./MyApi (for .NET) | builder.AddProject<Projects.MyApi>("myapi") | Direct .NET project reference |
Learn more about adding .NET projects.
Port mappings
Section titled “Port mappings”| Docker Compose | Aspire | Notes |
|---|---|---|
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 |
Learn more about Docker Compose ports and endpoint configuration.
Environment variables
Section titled “Environment variables”| Docker Compose | Aspire / 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+) |
Learn more about Docker Compose environment and external parameters.
Volumes and storage
Section titled “Volumes and storage”| Docker Compose | Aspire | Notes |
|---|---|---|
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 |
Learn more about Docker Compose volumes and persist container data.
Dependencies and ordering
Section titled “Dependencies and ordering”| Docker Compose | Aspire | Notes |
|---|---|---|
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 |
Learn more about Docker Compose depends_on and launch profiles.
Networks
Section titled “Networks”| Docker Compose | Aspire | Notes |
|---|---|---|
networks: [backend] | Automatic | Aspire handles networking automatically |
| Custom networks | Not needed | Service discovery handles inter-service communication |
Learn more about Docker Compose networks and service discovery.
Resource limits
Section titled “Resource limits”| Docker Compose | Aspire | Notes |
|---|---|---|
deploy.resources.limits.memory: 512m | Not supported | Resource limits aren’t supported in Aspire |
deploy.resources.limits.cpus: 0.5 | Not supported | Resource limits aren’t supported in Aspire |
Learn more about Docker Compose deploy reference.
Health checks
Section titled “Health checks”| Docker Compose | Aspire | Notes |
|---|---|---|
healthcheck.test: ["CMD", "curl", "http://localhost/health"] | Built-in for integrations | Aspire integrations include health checks |
healthcheck.interval: 30s | Configurable in integration | Health check configuration varies by resource type |
Learn more about Docker Compose healthcheck and health checks.
Restart policies
Section titled “Restart policies”| Docker Compose | Aspire | Notes |
|---|---|---|
restart: unless-stopped | Not supported | Restart policies aren’t supported in Aspire |
restart: always | Not supported | Restart policies aren’t supported in Aspire |
restart: no | Default | No restart policy |
Learn more about Docker Compose restart.
Logging
Section titled “Logging”| Docker Compose | Aspire | Notes |
|---|---|---|
logging.driver: json-file | Built-in | Aspire provides integrated logging |
logging.options.max-size: 10m | Dashboard configuration | Managed through Aspire dashboard |
Learn more about Docker Compose logging and telemetry.
Database services
Section titled “Database services”| Docker Compose | Aspire | Notes |
|---|---|---|
image: postgres:15 | builder.AddPostgres("name") | PostgreSQL with automatic configuration |
image: mysql:8 | builder.AddMySql("name") | MySQL with automatic configuration |
image: redis:7 | builder.AddRedis("name") | Redis with automatic configuration |
image: mongo:latest | builder.AddMongoDB("name") | MongoDB with automatic configuration |
Learn more about Docker Compose services and database integrations.