Skip to content
DocsTry Aspire
DocsTry

ContainerFilesExtensions Methods

ClassMethods2 members
Provides Dockerfile builder extension methods for supporting ResourceBuilderExtensions.PublishWithContainerFiles.
AddContainerFiles(DockerfileStage, IResource, string, ILogger?)Section titled AddContainerFiles(DockerfileStage, IResource, string, ILogger?)extensionDockerfileStage
Adds COPY --from statements to the Dockerfile stage for container files from resources referenced by ContainerFilesDestinationAnnotation.
public static class ContainerFilesExtensions
{
public static DockerfileStage AddContainerFiles(
this DockerfileStage stage,
IResource resource,
string rootDestinationPath,
ILogger? logger)
{
// ...
}
}
stageDockerfileStageThe Dockerfile stage to add container file copy statements to.
resourceIResourceThe resource that may have ContainerFilesDestinationAnnotation annotations specifying files to copy.
rootDestinationPathstringThe root destination path in the container. Relative paths in annotations will be appended to this path.
loggerILogger?The logger used for logging information or errors.
DockerfileStageThe DockerfileStage to allow for fluent chaining.

This method processes all ContainerFilesDestinationAnnotation annotations on the resource and generates COPY --from statements for each source container's files.

For each annotation:

  • If the source resource has a container image name (via TryGetContainerImageName), COPY statements are generated
  • If the source resource does not have a container image name, it is skipped
  • Relative destination paths are combined with rootDestinationPath
  • Absolute destination paths are used as-is
  • Each ContainerFilesSourceAnnotation on the source resource generates a COPY statement

This is typically used when building container images that need to include files from other containers, such as copying static assets from a frontend build container into a backend API container.

AddContainerFilesStages(DockerfileBuilder, IResource, ILogger?)Section titled AddContainerFilesStages(DockerfileBuilder, IResource, ILogger?)extensionDockerfileBuilder
Adds Dockerfile instructions to include container files from the specified resource into the Dockerfile build process.
public static class ContainerFilesExtensions
{
public static DockerfileBuilder AddContainerFilesStages(
this DockerfileBuilder builder,
IResource resource,
ILogger? logger)
{
// ...
}
}
builderDockerfileBuilderThe Dockerfile builder to which container file instructions will be added. Cannot be null.
resourceIResourceThe resource containing container files to be added to the Dockerfile. Cannot be null.
loggerILogger?An optional logger used to record warnings if container image names cannot be determined for source resources.
DockerfileBuilderThe same DockerfileBuilder instance with additional instructions for container files, enabling method chaining.