One of my favorite Aspire tricks is publishing your local orchestration to a plain Docker Compose file. No bespoke YAML hand-crafting: define your resources in C#, run one command, and get a production-shaped compose you can run anywhere Docker is available.
This post shows a tiny demo that publishes PostgreSQL, Redis, and the Aspire Dashboard to Docker Compose.
AppHost: enable the Docker publisher
var builder = DistributedApplication.CreateBuilder(args);
// Enables Docker publisher (gives the compose project a stable name)
builder.AddDockerComposeEnvironment("aspire-docker-demo");
var postgres = builder.AddPostgres("database")
.WithDataVolume();
var database = postgres.AddDatabase("demo-db");
var redis = builder.AddRedis("cache");
builder. Build().Run();
What this does
AddDockerComposeEnvironment("aspire-docker-demo")
Opts the app into the Docker publisher and sets the Compose project name (used for networks, volume names, etc.).- Postgres + volume
WithDataVolume()ensures a named Docker volume is created for data durability. AddDatabase("demo-db")
Declares a logical DB (helpful when apps bind to it; not strictly needed for Compose output).- Redis
Adds a simple cache service.
Publish to Docker Compose
From the AppHost directory:
aspire publish -o docker-compose-artifacts
This generates a docker-compose.yaml (and related files) under ./docker-compose-artifacts/.
