microsoft / microsoft/aspire

Optimize Docker Image Creation by Reusing Image Across The Same Project

Open
#10,537 0 comments 1 reaction 0 assignees View on GitHub
area-integrations
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

I'm working on creating a device emulator farm using Aspire. As part of the process, I generate a Docker Compose file when I publish the project.

Currently, the Compose file is generated correctly. However, during the publishing process, Aspire creates a separate custom Docker image for each device configuration. This significantly increases the time it takes to publish, especially when multiple devices share the same base setup.

Ideally, I'd like to build the image only once and reuse it across all device configurations, using the project name (or similar) as the container name. This would greatly reduce build times and improve overall efficiency.

```c#
foreach (var device in deviceConfigurations)
{
builder
.AddProject("device-" + device.Id)
.WithEnvironment($"{nameof(DeviceConfiguration)}:{nameof(DeviceConfiguration.Id)}", device.Id)
.WithEnvironment($"{nameof(DeviceConfiguration)}:{nameof(DeviceConfiguration.Base64Certificate)}", device.Base64Certificate)
.WithEnvironment($"{nameof(ProvisioningConfiguration)}:{nameof(ProvisioningConfiguration.GlobalDeviceEndpoint)}", provisioningConfiguration.GlobalDeviceEndpoint)
.WithEnvironment($"{nameof(ProvisioningConfiguration)}:{nameof(ProvisioningConfiguration.IdScope)}", provisioningConfiguration.IdScope);
}
```

### Describe the solution you'd like

If possible, we should build the image only once and use the project name as the container name during the loop. This way, we avoid building the same image multiple times for each project.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.