As dear @JeffFritz's (Microsoft MVP) quote :
The name of ConnectionString have to be same with the name that is specified in AppHost
In ConnectionString name of Host have to be same with the name that is specified for container name (Postgres)
Now that works for both .Net Aspire and Docker
"ConnectionStrings": {
"MyDatabase":"Host=Postgres;Port=5432;Database=MyDatabase;Username=postgres;Password=postgrespassword;"
}
var postgres = builder
.AddPostgres("Postgres", port: 5432)
.AddDatabase("MyDatabase");